{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from sklearn.tree import DecisionTreeRegressor\n",
    "from sklearn.datasets import load_breast_cancer\n",
    "from sklearn.model_selection import train_test_split\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import graphviz \n",
    "from sklearn.metrics import r2_score"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"data/titanic_train.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PassengerId</th>\n",
       "      <th>Survived</th>\n",
       "      <th>Pclass</th>\n",
       "      <th>Name</th>\n",
       "      <th>Sex</th>\n",
       "      <th>Age</th>\n",
       "      <th>SibSp</th>\n",
       "      <th>Parch</th>\n",
       "      <th>Ticket</th>\n",
       "      <th>Fare</th>\n",
       "      <th>Cabin</th>\n",
       "      <th>Embarked</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Braund, Mr. Owen Harris</td>\n",
       "      <td>male</td>\n",
       "      <td>22.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>A/5 21171</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Cumings, Mrs. John Bradley (Florence Briggs Th...</td>\n",
       "      <td>female</td>\n",
       "      <td>38.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>PC 17599</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>C85</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>Heikkinen, Miss. Laina</td>\n",
       "      <td>female</td>\n",
       "      <td>26.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>STON/O2. 3101282</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>Futrelle, Mrs. Jacques Heath (Lily May Peel)</td>\n",
       "      <td>female</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>113803</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>C123</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>Allen, Mr. William Henry</td>\n",
       "      <td>male</td>\n",
       "      <td>35.0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>373450</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>NaN</td>\n",
       "      <td>S</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   PassengerId  Survived  Pclass  \\\n",
       "0            1         0       3   \n",
       "1            2         1       1   \n",
       "2            3         1       3   \n",
       "3            4         1       1   \n",
       "4            5         0       3   \n",
       "\n",
       "                                                Name     Sex   Age  SibSp  \\\n",
       "0                            Braund, Mr. Owen Harris    male  22.0      1   \n",
       "1  Cumings, Mrs. John Bradley (Florence Briggs Th...  female  38.0      1   \n",
       "2                             Heikkinen, Miss. Laina  female  26.0      0   \n",
       "3       Futrelle, Mrs. Jacques Heath (Lily May Peel)  female  35.0      1   \n",
       "4                           Allen, Mr. William Henry    male  35.0      0   \n",
       "\n",
       "   Parch            Ticket     Fare Cabin Embarked  \n",
       "0      0         A/5 21171   7.2500   NaN        S  \n",
       "1      0          PC 17599  71.2833   C85        C  \n",
       "2      0  STON/O2. 3101282   7.9250   NaN        S  \n",
       "3      0            113803  53.1000  C123        S  \n",
       "4      0            373450   8.0500   NaN        S  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 891 entries, 0 to 890\n",
      "Data columns (total 12 columns):\n",
      " #   Column       Non-Null Count  Dtype  \n",
      "---  ------       --------------  -----  \n",
      " 0   PassengerId  891 non-null    int64  \n",
      " 1   Survived     891 non-null    int64  \n",
      " 2   Pclass       891 non-null    int64  \n",
      " 3   Name         891 non-null    object \n",
      " 4   Sex          891 non-null    object \n",
      " 5   Age          714 non-null    float64\n",
      " 6   SibSp        891 non-null    int64  \n",
      " 7   Parch        891 non-null    int64  \n",
      " 8   Ticket       891 non-null    object \n",
      " 9   Fare         891 non-null    float64\n",
      " 10  Cabin        204 non-null    object \n",
      " 11  Embarked     889 non-null    object \n",
      "dtypes: float64(2), int64(5), object(5)\n",
      "memory usage: 83.7+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def data_preprocess(df):\n",
    "    # Treat None as a category\n",
    "    df.loc[df['Embarked'].isna(), 'Embarked'] = 'U'\n",
    "    # Feature Preprocessing\n",
    "    del df['PassengerId']\n",
    "    del df['Name']\n",
    "    del df['Ticket']\n",
    "    del df['Cabin']\n",
    "    del df['Age']\n",
    "    #df.dropna(inplace=True)\n",
    "    d_sex={}\n",
    "    d_sex['male'] = 1\n",
    "    d_sex['female'] = 0\n",
    "\n",
    "    d_embarked = {}\n",
    "    d_embarked['S'] = 0\n",
    "    d_embarked['C'] = 1\n",
    "    d_embarked['Q'] = 2\n",
    "    d_embarked['U'] = 3\n",
    "\n",
    "    df['Sex'] = df['Sex'].apply(d_sex.get)\n",
    "    df['Sex'] = df['Sex'].astype(int)\n",
    "    df['Embarked'] = df['Embarked'].apply(d_embarked.get)\n",
    "    df['Embarked'] = df['Embarked'].astype(int)\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = data_preprocess(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 891 entries, 0 to 890\n",
      "Data columns (total 7 columns):\n",
      " #   Column    Non-Null Count  Dtype  \n",
      "---  ------    --------------  -----  \n",
      " 0   Survived  891 non-null    int64  \n",
      " 1   Pclass    891 non-null    int64  \n",
      " 2   Sex       891 non-null    int32  \n",
      " 3   SibSp     891 non-null    int64  \n",
      " 4   Parch     891 non-null    int64  \n",
      " 5   Fare      891 non-null    float64\n",
      " 6   Embarked  891 non-null    int32  \n",
      "dtypes: float64(1), int32(2), int64(4)\n",
      "memory usage: 41.9 KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Target Statistics\n",
    "Instead of doing target statistics in the algorithm, I choose to do it here."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "y = df['Survived']\n",
    "n = len(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3838383838383838"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "prior = y.sum()/n\n",
    "prior"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "prior_weight = 0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{3: 0.2425064479998356, 1: 0.6290619824107122, 2: 0.47258492786948075}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Pclass\n",
    "d_pclass={}\n",
    "pclass_values=df['Pclass'].unique()\n",
    "for v in pclass_values:\n",
    "    n_v = y[df['Pclass']==v].count()\n",
    "    sum_y = y[df['Pclass']==v].sum()\n",
    "    d_pclass[v] = (sum_y + prior_weight*prior) / (n_v + prior_weight)\n",
    "display(d_pclass)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1: 0.5355222873122635,\n",
       " 0: 0.34542632570570125,\n",
       " 3: 0.25405570860116317,\n",
       " 4: 0.17253617253617254,\n",
       " 2: 0.4628743576111997,\n",
       " 5: 0.03489439853076216,\n",
       " 8: 0.02558922558922559}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# SibSp\n",
    "d_sibsp={}\n",
    "psibsp_values=df['SibSp'].unique()\n",
    "for v in psibsp_values:\n",
    "    n_v = y[df['SibSp']==v].count()\n",
    "    sum_y = y[df['SibSp']==v].sum()\n",
    "    d_sibsp[v] = (sum_y + prior_weight*prior) / (n_v + prior_weight)\n",
    "display(d_sibsp)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: 0.34368742695935034,\n",
       " 1: 0.5501427779908793,\n",
       " 2: 0.49927849927849927,\n",
       " 5: 0.21671258034894397,\n",
       " 3: 0.5803489439853077,\n",
       " 4: 0.04264870931537598,\n",
       " 6: 0.12794612794612795}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Parch\n",
    "d_parch={}\n",
    "parch_values=df['Parch'].unique()\n",
    "for v in parch_values:\n",
    "    n_v = y[df['Parch']==v].count()\n",
    "    sum_y = y[df['Parch']==v].sum()\n",
    "    d_parch[v] = (sum_y + prior_weight*prior) / (n_v + prior_weight)\n",
    "display(d_parch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{0: 0.33699289246224856,\n",
       " 1: 0.5530677696849804,\n",
       " 2: 0.38957315086347344,\n",
       " 3: 0.8767676767676769}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Embarked\n",
    "d_embarked={}\n",
    "embarked_values=df['Embarked'].unique()\n",
    "for v in embarked_values:\n",
    "    n_v = y[df['Embarked']==v].count()\n",
    "    sum_y = y[df['Embarked']==v].sum()\n",
    "    d_embarked[v] = (sum_y + prior_weight*prior) / (n_v + prior_weight)\n",
    "display(d_embarked)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "def target_statistics(df):\n",
    "    df['Pclass']=df['Pclass'].apply(d_pclass.get)\n",
    "    df['SibSp']=df['SibSp'].apply(d_sibsp.get)\n",
    "    df['Parch']=df['Parch'].apply(d_parch.get)\n",
    "    df['Embarked']=df['Embarked'].apply(d_embarked.get)\n",
    "    return df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "df=target_statistics(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Survived</th>\n",
       "      <th>Pclass</th>\n",
       "      <th>Sex</th>\n",
       "      <th>SibSp</th>\n",
       "      <th>Parch</th>\n",
       "      <th>Fare</th>\n",
       "      <th>Embarked</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0.242506</td>\n",
       "      <td>1</td>\n",
       "      <td>0.535522</td>\n",
       "      <td>0.343687</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>0.336993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>0.629062</td>\n",
       "      <td>0</td>\n",
       "      <td>0.535522</td>\n",
       "      <td>0.343687</td>\n",
       "      <td>71.2833</td>\n",
       "      <td>0.553068</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0.242506</td>\n",
       "      <td>0</td>\n",
       "      <td>0.345426</td>\n",
       "      <td>0.343687</td>\n",
       "      <td>7.9250</td>\n",
       "      <td>0.336993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>0.629062</td>\n",
       "      <td>0</td>\n",
       "      <td>0.535522</td>\n",
       "      <td>0.343687</td>\n",
       "      <td>53.1000</td>\n",
       "      <td>0.336993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>0.242506</td>\n",
       "      <td>1</td>\n",
       "      <td>0.345426</td>\n",
       "      <td>0.343687</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>0.336993</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Survived    Pclass  Sex     SibSp     Parch     Fare  Embarked\n",
       "0         0  0.242506    1  0.535522  0.343687   7.2500  0.336993\n",
       "1         1  0.629062    0  0.535522  0.343687  71.2833  0.553068\n",
       "2         1  0.242506    0  0.345426  0.343687   7.9250  0.336993\n",
       "3         1  0.629062    0  0.535522  0.343687  53.1000  0.336993\n",
       "4         0  0.242506    1  0.345426  0.343687   8.0500  0.336993"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "y = df['Survived']\n",
    "y = np.array(y.values)\n",
    "X = df.drop('Survived', axis=1)\n",
    "X = np.array(X.values)\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y)\n",
    "n=X_train.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(668, 6)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(668,)"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_train.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Oblivious Tree\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "class SplitResult():\n",
    "    similarity = 0\n",
    "    similarity_gain = 0\n",
    "    i_feature = -1\n",
    "    split_value = None\n",
    "    split_quantile = 0\n",
    "    # left\n",
    "    left_X = None\n",
    "    left_y = None\n",
    "    left_y_previous = None\n",
    "    left_similarity = 0\n",
    "    left_n = 0\n",
    "    # right\n",
    "    right_X = None\n",
    "    right_y = None\n",
    "    right_y_previous = None\n",
    "    right_similarity = 0\n",
    "    right_n = 0\n",
    "\n",
    "\n",
    "class Level():\n",
    "    level = -1\n",
    "    similarity = 0\n",
    "    similarity_gain = 0\n",
    "    split_value = None\n",
    "    split_quantile = 0\n",
    "    splits = []\n",
    "    branches = []\n",
    "\n",
    "    def __init__(self):\n",
    "        self.splits = []\n",
    "        self.branches = []\n",
    "\n",
    "\n",
    "class Branch():\n",
    "    no = 0\n",
    "    depth = 1\n",
    "    i_feature = -1\n",
    "    split_value = 0\n",
    "    split_quantile = 0\n",
    "    similarity = 0\n",
    "    similarity_gain = 0\n",
    "    n_samples = 0\n",
    "    X = None\n",
    "    y = None\n",
    "    y_previous = None\n",
    "\n",
    "    left_branch = None\n",
    "    right_branch = None\n",
    "\n",
    "    def value(self, _lambda):\n",
    "        return np.sum(self.y)/(np.sum(self.y_previous * (1 - self.y_previous))+_lambda)\n",
    "\n",
    "    def is_leaf(self):\n",
    "        return self.left_branch is None and self.right_branch is None\n",
    "\n",
    "\n",
    "class ObliviousTree():\n",
    "\n",
    "    _lambda = 1\n",
    "    node_number = 0\n",
    "    tree = None\n",
    "    max_depth = 3\n",
    "    gamma = 2\n",
    "    colsample_bynode = 1.0\n",
    "    feature_splits = []\n",
    "    feature_names = []\n",
    "    verbose = False\n",
    "\n",
    "    def __init__(self, max_depth=3, _lambda=1, gamma=2, colsample_bynode=1.0, feature_names=[], verbose=False):\n",
    "\n",
    "        self.max_depth = max_depth\n",
    "        self._lambda = _lambda\n",
    "        self.gamma = gamma\n",
    "        self.colsample_bynode = colsample_bynode\n",
    "        self.feature_names = feature_names\n",
    "        self.verbose=verbose\n",
    "        self.feature_splits=[]\n",
    "        feature_names=[]\n",
    "\n",
    "    def get_similarity(self, y, y_previous):\n",
    "        sim = np.sum(y)**2/(np.sum(y_previous * (1-y_previous))+self._lambda)\n",
    "\n",
    "        return sim\n",
    "\n",
    "    def get_colsample_bynode_indics(self, n_features):\n",
    "        if n_features == 1:\n",
    "            return [1]\n",
    "\n",
    "        if self.colsample_bynode > 1:\n",
    "            raise ValueError(\n",
    "                \"colsample_bynode must be smaller than or equal to 1.0\")\n",
    "\n",
    "        n_selected_features = int(self.colsample_bynode * n_features)\n",
    "        if n_selected_features == n_features:\n",
    "            return list(range(n_features))\n",
    "\n",
    "        old_list = list(range(n_features))\n",
    "        new_list = []\n",
    "        for i in range(n_selected_features):\n",
    "            selected = random.choice(old_list)\n",
    "            while selected in new_list:\n",
    "                selected = random.choice(old_list)\n",
    "            new_list.append(selected)\n",
    "        return new_list\n",
    "\n",
    "    def find_best_split(self, X_all, X_list, y_list, y_previous_list):\n",
    "        n_list_len = len(y_list)\n",
    "        n_features = X_all.shape[1]\n",
    "        best_level = Level()\n",
    "\n",
    "        selected_features = self.get_colsample_bynode_indics(n_features)\n",
    "        for i_feature, split_value, split_quantile in self.feature_splits:\n",
    "            if not i_feature in selected_features:\n",
    "                continue\n",
    "            level = Level()\n",
    "            level.i_feature = i_feature\n",
    "            level.split_value = split_value\n",
    "            level.split_quantile = split_quantile\n",
    "            # strange, i have to write this otherwise splits will copy values from previous Level objects.\n",
    "            level.splits = []\n",
    "\n",
    "            similarities = []\n",
    "            for list_index in range(n_list_len):\n",
    "                X = X_list[list_index]\n",
    "                f = X[:, i_feature]\n",
    "                condition = f < split_value\n",
    "                y = y_list[list_index]\n",
    "                y_previous = y_previous_list[list_index]\n",
    "\n",
    "                # Approximate Algorithm\n",
    "                # Instead of Basic Exact Greedy Algorithm\n",
    "\n",
    "                sr = SplitResult()\n",
    "                sr.i_feature = level.i_feature\n",
    "                sr.split_quantile = level.split_quantile\n",
    "                sr.split_value = level.split_value\n",
    "                # print(condition)\n",
    "                # left\n",
    "                sr.left_X = X[condition, :]\n",
    "                sr.left_y = y[condition]\n",
    "                sr.left_y_previous = y_previous[condition]\n",
    "                sr.left_n = len(sr.left_y)\n",
    "                #if sr.left_n == 0:\n",
    "                #    continue\n",
    "                sr.left_similarity = self.get_similarity(\n",
    "                    sr.left_y, sr.left_y_previous)\n",
    "\n",
    "                # right\n",
    "                sr.right_X = X[~condition, :]\n",
    "                sr.right_y = y[~condition]\n",
    "                sr.right_y_previous = y_previous[~condition]\n",
    "                sr.right_n = len(sr.right_y)\n",
    "                # if sr.right_n == 0:\n",
    "                #    continue\n",
    "                sr.right_similarity = self.get_similarity(\n",
    "                    sr.right_y, sr.right_y_previous)\n",
    "\n",
    "                sr.similarity = sr.left_similarity + sr.right_similarity\n",
    "                similarities.append(sr.similarity)\n",
    "                level.splits.append(sr)\n",
    "            level.similarity = np.sum(similarities)\n",
    "            if level.similarity > best_level.similarity:\n",
    "                best_level = level\n",
    "        return best_level\n",
    "\n",
    "    def fit(self, X, y, y_previous):\n",
    "        \n",
    "        n_features = X.shape[1]\n",
    "        for i_feature in range(n_features):\n",
    "\n",
    "            f = X[:, i_feature]\n",
    "            quantiles = np.quantile(\n",
    "                f, [.1, .2, .3, .4, .5, .6, .7, .8, .9])\n",
    "            previous_split_value = f.min()\n",
    "            for split_value, split_quantile in zip(quantiles, [.1, .2, .3, .4, .5, .6, .7, .8, .9]):\n",
    "                if split_value == previous_split_value:\n",
    "                    continue\n",
    "                else:\n",
    "                    self.feature_splits.append(\n",
    "                        (i_feature, split_value, split_quantile))\n",
    "                previous_split_value = split_value\n",
    "\n",
    "        level_dict = {}\n",
    "        level0 = self.find_best_split(X, [X], [y], [y_previous])\n",
    "        #print(\"Feature\", \"Split_Value\", \"Split_Quantile\")\n",
    "        #print(level0.i_feature, level0.split_value, level0.split_quantile)\n",
    "        level_dict[0] = level0\n",
    "        branch_no=0\n",
    "        root = Branch()\n",
    "        root.no = branch_no\n",
    "        branch_no+=1\n",
    "        root.i_feature = level_dict[0].i_feature\n",
    "        root.split_value = level_dict[0].split_value\n",
    "        root.split_quantile = level_dict[0].split_quantile\n",
    "        root.X = X\n",
    "        root.y = y\n",
    "        root.y_previous = y_previous\n",
    "        root.n_samples = len(y)\n",
    "        level_dict[0].branches.append(root)\n",
    "        for level_no in range(1, self.max_depth):\n",
    "\n",
    "            X_list = []\n",
    "            y_list = []\n",
    "            y_previous_list = []\n",
    "\n",
    "            for sr in level_dict[level_no-1].splits:\n",
    "                X_list.append(sr.left_X)\n",
    "                X_list.append(sr.right_X)\n",
    "                y_list.append(sr.left_y)\n",
    "                y_list.append(sr.right_y)\n",
    "                y_previous_list.append(sr.left_y_previous)\n",
    "                y_previous_list.append(sr.right_y_previous)\n",
    "\n",
    "            if level_no==self.max_depth-1:\n",
    "                pass\n",
    "            else:\n",
    "                level_dict[level_no] = self.find_best_split(\n",
    "                    X, X_list, y_list, y_previous_list)\n",
    "\n",
    "            # build tree\n",
    "            previous_level = level_dict[level_no-1]\n",
    "            # splits = level_dict[level_no-1].splits\n",
    "            for sr_index, sr in enumerate(previous_level.splits):\n",
    "                parent_index = sr_index\n",
    "                parent_branch = previous_level.branches[parent_index]\n",
    "                # left branch\n",
    "                left_branch = Branch()\n",
    "                left_branch.no = branch_no\n",
    "                branch_no+=1\n",
    "\n",
    "                left_branch.X = level_dict[level_no - 1] \\\n",
    "                    .splits[parent_index].left_X\n",
    "                left_branch.y = level_dict[level_no - 1] \\\n",
    "                    .splits[parent_index].left_y\n",
    "                left_branch.y_previous = level_dict[level_no-1] \\\n",
    "                    .splits[parent_index].left_y_previous\n",
    "                left_branch.n_samples = len(left_branch.y)\n",
    "                parent_branch.left_branch = left_branch\n",
    "                if level_no!=self.max_depth-1:\n",
    "                    left_branch.i_feature = level_dict[level_no].i_feature\n",
    "                    left_branch.split_value = level_dict[level_no].split_value\n",
    "                    left_branch.split_quantile = level_dict[level_no].split_quantile\n",
    "                    level_dict[level_no].branches.append(left_branch)\n",
    "                # right branch\n",
    "                right_branch = Branch()\n",
    "                right_branch.no = branch_no\n",
    "                branch_no+=1\n",
    "\n",
    "                \n",
    "                right_branch.X = level_dict[level_no -\n",
    "                                            1].splits[parent_index].right_X\n",
    "                right_branch.y = level_dict[level_no -\n",
    "                                            1].splits[parent_index].right_y\n",
    "                right_branch.y_previous = level_dict[level_no -\n",
    "                                                     1].splits[parent_index].right_y_previous\n",
    "                right_branch.n_samples = len(right_branch.y)\n",
    "                parent_branch.right_branch = right_branch\n",
    "                if level_no!=self.max_depth-1:\n",
    "                    right_branch.i_feature = level_dict[level_no].i_feature\n",
    "                    right_branch.split_value = level_dict[level_no].split_value\n",
    "                    right_branch.split_quantile = level_dict[level_no].split_quantile\n",
    "                    level_dict[level_no].branches.append(right_branch)\n",
    "\n",
    "        self.tree = root\n",
    "        return root\n",
    "\n",
    "    def predict_one_inner(self, tree: Branch, x):\n",
    "        if tree.is_leaf():\n",
    "            return tree.value(self._lambda)\n",
    "        if x[tree.i_feature] < tree.split_value:\n",
    "            return self.predict_one_inner(tree.left_branch, x)\n",
    "        else:\n",
    "            return self.predict_one_inner(tree.right_branch, x)\n",
    "\n",
    "    def predict_inner(self, tree: Branch, X):\n",
    "        y = []\n",
    "        for x in X:\n",
    "            t = self.predict_one_inner(tree, x)\n",
    "            y.append(t)\n",
    "        return np.array(y)\n",
    "\n",
    "    def predict(self, X):\n",
    "        return self.predict_inner(self.tree, X)\n",
    "\n",
    "    def score(self, X, y):\n",
    "        y_hat = self.predict(X)\n",
    "        return r2_score(y, y_hat)\n",
    "\n",
    "    def export_graphviz_inner(self, the_branch: Branch, dot_data: str):\n",
    "        fillcolor = \"#ffffff\"\n",
    "        colors=[\"#04b0f1\", \"#6c7115\", \"#e96b4c\", \"#d72203\", \"#eb05f4\", \"#b0c48b\", \"#7a2c1c\", \"#207dfb\"]\n",
    "\n",
    "\n",
    "        if the_branch.is_leaf():\n",
    "            n_positive = sum(the_branch.y >= 0)\n",
    "            n_negative = sum(the_branch.y < 0)\n",
    "            dot_data += f\"{the_branch.no} [label=\\\"{the_branch.no}\\n\" +  \\\n",
    "                f\"samples={the_branch.n_samples:0.0f}\\\\n\" + \\\n",
    "                f\"+/- = {n_positive}/{n_negative}\\\\n\" + \\\n",
    "                f\"value={the_branch.value(self._lambda):0.3f}\\\\n\" + \\\n",
    "                f\"\\\", fillcolor=\\\"{colors[the_branch.i_feature]}\\\"];\"\n",
    "        else:\n",
    "            dot_data += f\"{the_branch.no} [label=\\\"{the_branch.no}\\n\" + \\\n",
    "                f\"{self.feature_names[the_branch.i_feature]} < {the_branch.split_value:0.3f}\\\\n\" + \\\n",
    "                f\"split_quantile = {the_branch.split_quantile:0.1f}\\\\n\" + f\"samples = {the_branch.n_samples:0.0f}\\\\n\" + \\\n",
    "                f\"\\\", fillcolor=\\\"{colors[the_branch.i_feature]}\\\"];\"\n",
    "\n",
    "        if not the_branch.left_branch is None:\n",
    "            left_branch = the_branch.left_branch\n",
    "            if left_branch.no > 0:\n",
    "                dot_data += f\"{the_branch.no} -> {left_branch.no} [label=\\\"yes\\\"];\"\n",
    "                dot_data = self.export_graphviz_inner(left_branch, dot_data)\n",
    "        if not the_branch.right_branch is None:\n",
    "            right_branch = the_branch.right_branch\n",
    "            if right_branch.no > 0:\n",
    "                dot_data += f\"{the_branch.no} -> {right_branch.no}  [label=\\\"no\\\"];\"\n",
    "                dot_data = self.export_graphviz_inner(right_branch, dot_data)\n",
    "        return dot_data\n",
    "\n",
    "    def export_graphviz(self):\n",
    "        dot_data = \"\"\"digraph Tree {\\nnode [shape=box, style=\"filled, rounded\", color=\"black\", fontname=helvetica] ;\\nedge [fontname=helvetica] ;\\n\"\"\"\n",
    "        dot_data += self.export_graphviz_inner(self.tree, \"\")\n",
    "        dot_data += \"}\"\n",
    "        dot_data = dot_data.replace(\"\\r\\n\", \"\\n\")\n",
    "        return dot_data\n",
    "\n",
    "    def get_feature_split_table(self):\n",
    "        df=pd.DataFrame()\n",
    "        for f, sv, sq in self.feature_splits:\n",
    "            df=df.append({'feature':f, 'split_value': sv, 'split_quantitle': sq}, ignore_index=True)\n",
    "        return df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Try the Tree"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\r\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\r\n",
       "<!-- Generated by graphviz version 2.38.0 (20140413.2041)\r\n",
       " -->\r\n",
       "<!-- Title: Tree Pages: 1 -->\r\n",
       "<svg width=\"926pt\" height=\"433pt\"\r\n",
       " viewBox=\"0.00 0.00 925.50 433.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 429)\">\r\n",
       "<title>Tree</title>\r\n",
       "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-429 921.5,-429 921.5,4 -4,4\"/>\r\n",
       "<!-- 0 -->\r\n",
       "<g id=\"node1\" class=\"node\"><title>0</title>\r\n",
       "<path fill=\"#6c7115\" stroke=\"black\" d=\"M507,-425C507,-425 396,-425 396,-425 390,-425 384,-419 384,-413 384,-413 384,-369 384,-369 384,-363 390,-357 396,-357 396,-357 507,-357 507,-357 513,-357 519,-363 519,-369 519,-369 519,-413 519,-413 519,-419 513,-425 507,-425\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-409.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-394.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Sex &lt; 1.000</text>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-379.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-364.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 668</text>\r\n",
       "</g>\r\n",
       "<!-- 1 -->\r\n",
       "<g id=\"node2\" class=\"node\"><title>1</title>\r\n",
       "<path fill=\"#04b0f1\" stroke=\"black\" d=\"M400,-306C400,-306 289,-306 289,-306 283,-306 277,-300 277,-294 277,-294 277,-250 277,-250 277,-244 283,-238 289,-238 289,-238 400,-238 400,-238 406,-238 412,-244 412,-250 412,-250 412,-294 412,-294 412,-300 406,-306 400,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Pclass &lt; 0.243</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 217</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;1 -->\r\n",
       "<g id=\"edge1\" class=\"edge\"><title>0&#45;&gt;1</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M421.124,-356.785C408.926,-343.447 394.741,-327.936 381.916,-313.912\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"384.283,-311.315 374.952,-306.298 379.118,-316.039 384.283,-311.315\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"416\" y=\"-327.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 2 -->\r\n",
       "<g id=\"node9\" class=\"node\"><title>2</title>\r\n",
       "<path fill=\"#04b0f1\" stroke=\"black\" d=\"M581,-306C581,-306 470,-306 470,-306 464,-306 458,-300 458,-294 458,-294 458,-250 458,-250 458,-244 464,-238 470,-238 470,-238 581,-238 581,-238 587,-238 593,-244 593,-250 593,-250 593,-294 593,-294 593,-300 587,-306 581,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">2</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Pclass &lt; 0.243</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 451</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;2 -->\r\n",
       "<g id=\"edge8\" class=\"edge\"><title>0&#45;&gt;2</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M472.507,-356.785C480.71,-343.817 490.21,-328.796 498.882,-315.084\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"502.053,-316.62 504.44,-306.298 496.137,-312.878 502.053,-316.62\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"501.5\" y=\"-327.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 3 -->\r\n",
       "<g id=\"node3\" class=\"node\"><title>3</title>\r\n",
       "<path fill=\"#eb05f4\" stroke=\"black\" d=\"M218,-187C218,-187 107,-187 107,-187 101,-187 95,-181 95,-175 95,-175 95,-131 95,-131 95,-125 101,-119 107,-119 107,-119 218,-119 218,-119 224,-119 230,-125 230,-131 230,-131 230,-175 230,-175 230,-181 224,-187 218,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">3</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Fare &lt; 24.030</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 100</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;3 -->\r\n",
       "<g id=\"edge2\" class=\"edge\"><title>1&#45;&gt;3</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M292.833,-237.785C270.934,-223.708 245.272,-207.21 222.537,-192.595\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"224.286,-189.558 213.981,-187.095 220.5,-195.447 224.286,-189.558\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"276\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 4 -->\r\n",
       "<g id=\"node6\" class=\"node\"><title>4</title>\r\n",
       "<path fill=\"#eb05f4\" stroke=\"black\" d=\"M400,-187C400,-187 289,-187 289,-187 283,-187 277,-181 277,-175 277,-175 277,-131 277,-131 277,-125 283,-119 289,-119 289,-119 400,-119 400,-119 406,-119 412,-125 412,-131 412,-131 412,-175 412,-175 412,-181 406,-187 400,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Fare &lt; 24.030</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 117</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;4 -->\r\n",
       "<g id=\"edge5\" class=\"edge\"><title>1&#45;&gt;4</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M344.5,-237.785C344.5,-225.311 344.5,-210.938 344.5,-197.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"348,-197.298 344.5,-187.298 341,-197.298 348,-197.298\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"352.5\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 7 -->\r\n",
       "<g id=\"node4\" class=\"node\"><title>7</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M83,-68C83,-68 12,-68 12,-68 6,-68 0,-62 0,-56 0,-56 0,-12 0,-12 0,-6 6,-0 12,-0 12,-0 83,-0 83,-0 89,-0 95,-6 95,-12 95,-12 95,-56 95,-56 95,-62 89,-68 83,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">7</text>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=79</text>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 51/28</text>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.554</text>\r\n",
       "</g>\r\n",
       "<!-- 3&#45;&gt;7 -->\r\n",
       "<g id=\"edge3\" class=\"edge\"><title>3&#45;&gt;7</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M129.853,-118.785C116.621,-105.323 101.215,-89.6488 87.3305,-75.5233\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"89.7344,-72.9759 80.2284,-68.2976 84.7422,-77.8828 89.7344,-72.9759\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"124\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 8 -->\r\n",
       "<g id=\"node5\" class=\"node\"><title>8</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M200,-68C200,-68 125,-68 125,-68 119,-68 113,-62 113,-56 113,-56 113,-12 113,-12 113,-6 119,-0 125,-0 125,-0 200,-0 200,-0 206,-0 212,-6 212,-12 212,-12 212,-56 212,-56 212,-62 206,-68 200,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">8</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=21</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 3/18</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;1.200</text>\r\n",
       "</g>\r\n",
       "<!-- 3&#45;&gt;8 -->\r\n",
       "<g id=\"edge4\" class=\"edge\"><title>3&#45;&gt;8</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M162.5,-118.785C162.5,-106.311 162.5,-91.9377 162.5,-78.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"166,-78.2976 162.5,-68.2976 159,-78.2976 166,-78.2976\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"170.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 9 -->\r\n",
       "<g id=\"node7\" class=\"node\"><title>9</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M313,-68C313,-68 242,-68 242,-68 236,-68 230,-62 230,-56 230,-56 230,-12 230,-12 230,-6 236,-0 242,-0 242,-0 313,-0 313,-0 319,-0 325,-6 325,-12 325,-12 325,-56 325,-56 325,-62 319,-68 313,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">9</text>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=26</text>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 22/4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=1.200</text>\r\n",
       "</g>\r\n",
       "<!-- 4&#45;&gt;9 -->\r\n",
       "<g id=\"edge6\" class=\"edge\"><title>4&#45;&gt;9</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M325.48,-118.785C318.053,-105.817 309.452,-90.7962 301.6,-77.0844\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"304.575,-75.2362 296.568,-68.2976 298.5,-78.7148 304.575,-75.2362\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"327\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 10 -->\r\n",
       "<g id=\"node8\" class=\"node\"><title>10</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M426,-68C426,-68 355,-68 355,-68 349,-68 343,-62 343,-56 343,-56 343,-12 343,-12 343,-6 349,-0 355,-0 355,-0 426,-0 426,-0 432,-0 438,-6 438,-12 438,-12 438,-56 438,-56 438,-62 432,-68 426,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">10</text>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=91</text>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 87/4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=1.747</text>\r\n",
       "</g>\r\n",
       "<!-- 4&#45;&gt;10 -->\r\n",
       "<g id=\"edge7\" class=\"edge\"><title>4&#45;&gt;10</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M357.559,-118.785C362.56,-106.064 368.338,-91.3677 373.645,-77.8694\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"377.007,-78.8848 377.409,-68.2976 370.492,-76.3235 377.007,-78.8848\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"378.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 5 -->\r\n",
       "<g id=\"node10\" class=\"node\"><title>5</title>\r\n",
       "<path fill=\"#eb05f4\" stroke=\"black\" d=\"M581,-187C581,-187 470,-187 470,-187 464,-187 458,-181 458,-175 458,-175 458,-131 458,-131 458,-125 464,-119 470,-119 470,-119 581,-119 581,-119 587,-119 593,-125 593,-131 593,-131 593,-175 593,-175 593,-181 587,-187 581,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">5</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Fare &lt; 24.030</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 273</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;5 -->\r\n",
       "<g id=\"edge9\" class=\"edge\"><title>2&#45;&gt;5</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M525.5,-237.785C525.5,-225.311 525.5,-210.938 525.5,-197.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"529,-197.298 525.5,-187.298 522,-197.298 529,-197.298\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"537\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 6 -->\r\n",
       "<g id=\"node13\" class=\"node\"><title>6</title>\r\n",
       "<path fill=\"#eb05f4\" stroke=\"black\" d=\"M801,-187C801,-187 690,-187 690,-187 684,-187 678,-181 678,-175 678,-175 678,-131 678,-131 678,-125 684,-119 690,-119 690,-119 801,-119 801,-119 807,-119 813,-125 813,-131 813,-131 813,-175 813,-175 813,-181 807,-187 801,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Fare &lt; 24.030</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 178</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;6 -->\r\n",
       "<g id=\"edge12\" class=\"edge\"><title>2&#45;&gt;6</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M587.661,-237.942C614.605,-223.612 646.305,-206.754 674.199,-191.919\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"675.926,-194.965 683.111,-187.179 672.639,-188.785 675.926,-194.965\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"657.5\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 11 -->\r\n",
       "<g id=\"node11\" class=\"node\"><title>11</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M548.5,-68C548.5,-68 468.5,-68 468.5,-68 462.5,-68 456.5,-62 456.5,-56 456.5,-56 456.5,-12 456.5,-12 456.5,-6 462.5,-0 468.5,-0 468.5,-0 548.5,-0 548.5,-0 554.5,-0 560.5,-6 560.5,-12 560.5,-12 560.5,-56 560.5,-56 560.5,-62 554.5,-68 548.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">11</text>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=239</text>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 34/205</text>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;1.407</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;11 -->\r\n",
       "<g id=\"edge10\" class=\"edge\"><title>5&#45;&gt;11</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M520.674,-118.785C518.844,-106.188 516.732,-91.6529 514.786,-78.2629\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"518.24,-77.6904 513.338,-68.2976 511.312,-78.697 518.24,-77.6904\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"530\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 12 -->\r\n",
       "<g id=\"node12\" class=\"node\"><title>12</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M666,-68C666,-68 591,-68 591,-68 585,-68 579,-62 579,-56 579,-56 579,-12 579,-12 579,-6 585,-0 591,-0 591,-0 666,-0 666,-0 672,-0 678,-6 678,-12 678,-12 678,-56 678,-56 678,-62 672,-68 666,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">12</text>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=34</text>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 3/31</text>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;1.474</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;12 -->\r\n",
       "<g id=\"edge11\" class=\"edge\"><title>5&#45;&gt;12</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M554.74,-118.785C566.483,-105.447 580.137,-89.9362 592.483,-75.9124\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"595.206,-78.1162 599.187,-68.2976 589.952,-73.4908 595.206,-78.1162\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"591.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 13 -->\r\n",
       "<g id=\"node14\" class=\"node\"><title>13</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M783,-68C783,-68 708,-68 708,-68 702,-68 696,-62 696,-56 696,-56 696,-12 696,-12 696,-6 702,-0 708,-0 708,-0 783,-0 783,-0 789,-0 795,-6 795,-12 795,-12 795,-56 795,-56 795,-62 789,-68 783,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">13</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=57</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 6/51</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;1.475</text>\r\n",
       "</g>\r\n",
       "<!-- 6&#45;&gt;13 -->\r\n",
       "<g id=\"edge13\" class=\"edge\"><title>6&#45;&gt;13</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M745.5,-118.785C745.5,-106.311 745.5,-91.9377 745.5,-78.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"749,-78.2976 745.5,-68.2976 742,-78.2976 749,-78.2976\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"757\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 14 -->\r\n",
       "<g id=\"node15\" class=\"node\"><title>14</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M905.5,-68C905.5,-68 825.5,-68 825.5,-68 819.5,-68 813.5,-62 813.5,-56 813.5,-56 813.5,-12 813.5,-12 813.5,-6 819.5,-0 825.5,-0 825.5,-0 905.5,-0 905.5,-0 911.5,-0 917.5,-6 917.5,-12 917.5,-12 917.5,-56 917.5,-56 917.5,-62 911.5,-68 905.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"865.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">14</text>\r\n",
       "<text text-anchor=\"middle\" x=\"865.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=121</text>\r\n",
       "<text text-anchor=\"middle\" x=\"865.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 40/81</text>\r\n",
       "<text text-anchor=\"middle\" x=\"865.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.656</text>\r\n",
       "</g>\r\n",
       "<!-- 6&#45;&gt;14 -->\r\n",
       "<g id=\"edge14\" class=\"edge\"><title>6&#45;&gt;14</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M779.566,-118.785C793.374,-105.323 809.45,-89.6488 823.938,-75.5233\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"826.632,-77.7846 831.349,-68.2976 821.745,-72.7726 826.632,-77.7846\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"821.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "</g>\r\n",
       "</svg>\r\n"
      ],
      "text/plain": [
       "<graphviz.files.Source at 0x21f1000c3a0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "y_train0 = np.array([0.5] * len(y_train)) \n",
    "feature_names = ['Pclass', 'Sex',\n",
    "                 'SibSp', 'Parch', 'Fare', 'Embarked']\n",
    "ot = ObliviousTree(max_depth=4, feature_names=feature_names, verbose=True)\n",
    "ot.fit(X_train, y_train-y_train0, y_train0)\n",
    "dot_data=ot.export_graphviz()\n",
    "\n",
    "graph = graphviz.Source(dot_data) \n",
    "display(graph)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>feature</th>\n",
       "      <th>split_quantitle</th>\n",
       "      <th>split_value</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.1</td>\n",
       "      <td>0.242506</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.3</td>\n",
       "      <td>0.242506</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.472585</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.8</td>\n",
       "      <td>0.629062</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.0</td>\n",
       "      <td>0.4</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2.0</td>\n",
       "      <td>0.1</td>\n",
       "      <td>0.345426</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2.0</td>\n",
       "      <td>0.8</td>\n",
       "      <td>0.535522</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>3.0</td>\n",
       "      <td>0.1</td>\n",
       "      <td>0.343687</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>3.0</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.343687</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>3.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.343687</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>3.0</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.343687</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>3.0</td>\n",
       "      <td>0.7</td>\n",
       "      <td>0.343687</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>3.0</td>\n",
       "      <td>0.8</td>\n",
       "      <td>0.499278</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>3.0</td>\n",
       "      <td>0.9</td>\n",
       "      <td>0.550143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>4.0</td>\n",
       "      <td>0.1</td>\n",
       "      <td>7.550000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>4.0</td>\n",
       "      <td>0.2</td>\n",
       "      <td>7.879200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>4.0</td>\n",
       "      <td>0.3</td>\n",
       "      <td>8.050000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>4.0</td>\n",
       "      <td>0.4</td>\n",
       "      <td>10.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>4.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>14.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>4.0</td>\n",
       "      <td>0.6</td>\n",
       "      <td>24.030000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>4.0</td>\n",
       "      <td>0.7</td>\n",
       "      <td>27.747080</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>4.0</td>\n",
       "      <td>0.8</td>\n",
       "      <td>39.687500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>4.0</td>\n",
       "      <td>0.9</td>\n",
       "      <td>77.958300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>5.0</td>\n",
       "      <td>0.4</td>\n",
       "      <td>0.336993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>5.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.336993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>5.0</td>\n",
       "      <td>0.6</td>\n",
       "      <td>0.336993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>5.0</td>\n",
       "      <td>0.7</td>\n",
       "      <td>0.336993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>5.0</td>\n",
       "      <td>0.8</td>\n",
       "      <td>0.389573</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>5.0</td>\n",
       "      <td>0.9</td>\n",
       "      <td>0.553068</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    feature  split_quantitle  split_value\n",
       "0       0.0              0.1     0.242506\n",
       "1       0.0              0.3     0.242506\n",
       "2       0.0              0.6     0.472585\n",
       "3       0.0              0.8     0.629062\n",
       "4       1.0              0.4     1.000000\n",
       "5       2.0              0.1     0.345426\n",
       "6       2.0              0.8     0.535522\n",
       "7       3.0              0.1     0.343687\n",
       "8       3.0              0.4     0.343687\n",
       "9       3.0              0.5     0.343687\n",
       "10      3.0              0.6     0.343687\n",
       "11      3.0              0.7     0.343687\n",
       "12      3.0              0.8     0.499278\n",
       "13      3.0              0.9     0.550143\n",
       "14      4.0              0.1     7.550000\n",
       "15      4.0              0.2     7.879200\n",
       "16      4.0              0.3     8.050000\n",
       "17      4.0              0.4    10.500000\n",
       "18      4.0              0.5    14.500000\n",
       "19      4.0              0.6    24.030000\n",
       "20      4.0              0.7    27.747080\n",
       "21      4.0              0.8    39.687500\n",
       "22      4.0              0.9    77.958300\n",
       "23      5.0              0.4     0.336993\n",
       "24      5.0              0.5     0.336993\n",
       "25      5.0              0.6     0.336993\n",
       "26      5.0              0.7     0.336993\n",
       "27      5.0              0.8     0.389573\n",
       "28      5.0              0.9     0.553068"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ot.get_feature_split_table()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 1 Average"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "n_train = len(y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_train = pd.DataFrame()\n",
    "df_train['y'] = np.array(y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>y</th>\n",
       "      <th>$f_0$</th>\n",
       "      <th>$r_0$</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-0.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-0.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-0.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-0.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>663</th>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-0.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>664</th>\n",
       "      <td>1</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>665</th>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-0.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>666</th>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-0.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>667</th>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>-0.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>668 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     y  $f_0$  $r_0$\n",
       "0    0    1.0   -0.5\n",
       "1    0    1.0   -0.5\n",
       "2    1    1.0    0.5\n",
       "3    0    1.0   -0.5\n",
       "4    0    1.0   -0.5\n",
       "..  ..    ...    ...\n",
       "663  0    1.0   -0.5\n",
       "664  1    1.0    0.5\n",
       "665  0    1.0   -0.5\n",
       "666  0    1.0   -0.5\n",
       "667  0    1.0   -0.5\n",
       "\n",
       "[668 rows x 3 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.6931471805599453\n"
     ]
    }
   ],
   "source": [
    "#now let's get started\n",
    "learning_rate=0.5\n",
    "loss = [0] * 6\n",
    "residuals = np.zeros([6,n_train])\n",
    "probabilities = np.zeros([6,n_train])\n",
    "predictions = np.zeros([6,n_train])\n",
    "log_of_odds = np.zeros([6,n_train])\n",
    "gamma = np.zeros([6,n_train])\n",
    "log_of_odds[0] = [0] * n_train\n",
    "#calculation\n",
    "#average_y=y.mean()\n",
    "probabilities[0] = [0.5] * n_train\n",
    "predictions[0] = [1] * n_train\n",
    "residuals[0] = y_train - probabilities[0]\n",
    "df_train['$f_0$']=np.array(predictions[0]).reshape((-1, 1))\n",
    "df_train['$r_0$']=np.array(residuals[0]).reshape((-1, 1))\n",
    "display(df_train)\n",
    "loss0=-(y_train*np.log(probabilities[0])+(1-y_train)*np.log(1-probabilities[0]))\n",
    "loss[0] = np.sum(loss0) / n_train\n",
    "print(loss[0])\n",
    "trees = []"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 2 For Loop"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "def iterate(i):\n",
    "    t = ObliviousTree(max_depth=4, gamma=5, feature_names=feature_names)\n",
    "    t.fit(X_train,residuals[i], probabilities[i])\n",
    "    trees.append(t)\n",
    "    \n",
    "    dot_data = t.export_graphviz()\n",
    "    graph = graphviz.Source(dot_data) \n",
    "    display(graph)\n",
    "\n",
    "    #next prediction, residual\n",
    "    gamma[i]=t.predict(X_train)\n",
    "    log_of_odds[i+1] = log_of_odds[i] + 0.5 * gamma[i]\n",
    "    probabilities[i+1] = np.array([np.exp(odds)/(np.exp(odds)+1) for odds in log_of_odds[i+1]])\n",
    "    predictions[i+1] = (probabilities[i+1]>0.5)*1.0\n",
    "    residuals[i+1]=y_train-probabilities[i+1]\n",
    "    loss[i+1]=np.sum(-y_train * log_of_odds[i+1] + np.log(1+np.exp(log_of_odds[i+1])))\n",
    "    loss[i+1]=loss[i+1]/n_train\n",
    "    y_hat=t.predict(X_train)\n",
    "    \n",
    "    new_df=pd.DataFrame()\n",
    "    new_df['y']=y_train\n",
    "    new_df[f'$p_{i}$']=probabilities[i]\n",
    "    new_df[f'$l_{i}$']=log_of_odds[i]\n",
    "    new_df[f'$r_{i}$']=residuals[i]\n",
    "    new_df[f'$\\gamma_{i}$']=gamma[i]\n",
    "    new_df[f'$l_{i+1}$']=log_of_odds[i+1]\n",
    "    new_df[f'$p_{i+1}$']=probabilities[i+1]\n",
    "    display(new_df)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\r\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\r\n",
       "<!-- Generated by graphviz version 2.38.0 (20140413.2041)\r\n",
       " -->\r\n",
       "<!-- Title: Tree Pages: 1 -->\r\n",
       "<svg width=\"926pt\" height=\"433pt\"\r\n",
       " viewBox=\"0.00 0.00 925.50 433.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 429)\">\r\n",
       "<title>Tree</title>\r\n",
       "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-429 921.5,-429 921.5,4 -4,4\"/>\r\n",
       "<!-- 0 -->\r\n",
       "<g id=\"node1\" class=\"node\"><title>0</title>\r\n",
       "<path fill=\"#6c7115\" stroke=\"black\" d=\"M507,-425C507,-425 396,-425 396,-425 390,-425 384,-419 384,-413 384,-413 384,-369 384,-369 384,-363 390,-357 396,-357 396,-357 507,-357 507,-357 513,-357 519,-363 519,-369 519,-369 519,-413 519,-413 519,-419 513,-425 507,-425\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-409.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-394.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Sex &lt; 1.000</text>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-379.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-364.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 668</text>\r\n",
       "</g>\r\n",
       "<!-- 1 -->\r\n",
       "<g id=\"node2\" class=\"node\"><title>1</title>\r\n",
       "<path fill=\"#04b0f1\" stroke=\"black\" d=\"M400,-306C400,-306 289,-306 289,-306 283,-306 277,-300 277,-294 277,-294 277,-250 277,-250 277,-244 283,-238 289,-238 289,-238 400,-238 400,-238 406,-238 412,-244 412,-250 412,-250 412,-294 412,-294 412,-300 406,-306 400,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Pclass &lt; 0.243</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 217</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;1 -->\r\n",
       "<g id=\"edge1\" class=\"edge\"><title>0&#45;&gt;1</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M421.124,-356.785C408.926,-343.447 394.741,-327.936 381.916,-313.912\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"384.283,-311.315 374.952,-306.298 379.118,-316.039 384.283,-311.315\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"416\" y=\"-327.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 2 -->\r\n",
       "<g id=\"node9\" class=\"node\"><title>2</title>\r\n",
       "<path fill=\"#04b0f1\" stroke=\"black\" d=\"M581,-306C581,-306 470,-306 470,-306 464,-306 458,-300 458,-294 458,-294 458,-250 458,-250 458,-244 464,-238 470,-238 470,-238 581,-238 581,-238 587,-238 593,-244 593,-250 593,-250 593,-294 593,-294 593,-300 587,-306 581,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">2</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Pclass &lt; 0.243</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 451</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;2 -->\r\n",
       "<g id=\"edge8\" class=\"edge\"><title>0&#45;&gt;2</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M472.507,-356.785C480.71,-343.817 490.21,-328.796 498.882,-315.084\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"502.053,-316.62 504.44,-306.298 496.137,-312.878 502.053,-316.62\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"501.5\" y=\"-327.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 3 -->\r\n",
       "<g id=\"node3\" class=\"node\"><title>3</title>\r\n",
       "<path fill=\"#eb05f4\" stroke=\"black\" d=\"M218,-187C218,-187 107,-187 107,-187 101,-187 95,-181 95,-175 95,-175 95,-131 95,-131 95,-125 101,-119 107,-119 107,-119 218,-119 218,-119 224,-119 230,-125 230,-131 230,-131 230,-175 230,-175 230,-181 224,-187 218,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">3</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Fare &lt; 24.030</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 100</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;3 -->\r\n",
       "<g id=\"edge2\" class=\"edge\"><title>1&#45;&gt;3</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M292.833,-237.785C270.934,-223.708 245.272,-207.21 222.537,-192.595\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"224.286,-189.558 213.981,-187.095 220.5,-195.447 224.286,-189.558\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"276\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 4 -->\r\n",
       "<g id=\"node6\" class=\"node\"><title>4</title>\r\n",
       "<path fill=\"#eb05f4\" stroke=\"black\" d=\"M400,-187C400,-187 289,-187 289,-187 283,-187 277,-181 277,-175 277,-175 277,-131 277,-131 277,-125 283,-119 289,-119 289,-119 400,-119 400,-119 406,-119 412,-125 412,-131 412,-131 412,-175 412,-175 412,-181 406,-187 400,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Fare &lt; 24.030</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 117</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;4 -->\r\n",
       "<g id=\"edge5\" class=\"edge\"><title>1&#45;&gt;4</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M344.5,-237.785C344.5,-225.311 344.5,-210.938 344.5,-197.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"348,-197.298 344.5,-187.298 341,-197.298 348,-197.298\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"352.5\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 7 -->\r\n",
       "<g id=\"node4\" class=\"node\"><title>7</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M83,-68C83,-68 12,-68 12,-68 6,-68 0,-62 0,-56 0,-56 0,-12 0,-12 0,-6 6,-0 12,-0 12,-0 83,-0 83,-0 89,-0 95,-6 95,-12 95,-12 95,-56 95,-56 95,-62 89,-68 83,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">7</text>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=79</text>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 51/28</text>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.554</text>\r\n",
       "</g>\r\n",
       "<!-- 3&#45;&gt;7 -->\r\n",
       "<g id=\"edge3\" class=\"edge\"><title>3&#45;&gt;7</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M129.853,-118.785C116.621,-105.323 101.215,-89.6488 87.3305,-75.5233\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"89.7344,-72.9759 80.2284,-68.2976 84.7422,-77.8828 89.7344,-72.9759\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"124\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 8 -->\r\n",
       "<g id=\"node5\" class=\"node\"><title>8</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M200,-68C200,-68 125,-68 125,-68 119,-68 113,-62 113,-56 113,-56 113,-12 113,-12 113,-6 119,-0 125,-0 125,-0 200,-0 200,-0 206,-0 212,-6 212,-12 212,-12 212,-56 212,-56 212,-62 206,-68 200,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">8</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=21</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 3/18</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;1.200</text>\r\n",
       "</g>\r\n",
       "<!-- 3&#45;&gt;8 -->\r\n",
       "<g id=\"edge4\" class=\"edge\"><title>3&#45;&gt;8</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M162.5,-118.785C162.5,-106.311 162.5,-91.9377 162.5,-78.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"166,-78.2976 162.5,-68.2976 159,-78.2976 166,-78.2976\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"170.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 9 -->\r\n",
       "<g id=\"node7\" class=\"node\"><title>9</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M313,-68C313,-68 242,-68 242,-68 236,-68 230,-62 230,-56 230,-56 230,-12 230,-12 230,-6 236,-0 242,-0 242,-0 313,-0 313,-0 319,-0 325,-6 325,-12 325,-12 325,-56 325,-56 325,-62 319,-68 313,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">9</text>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=26</text>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 22/4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=1.200</text>\r\n",
       "</g>\r\n",
       "<!-- 4&#45;&gt;9 -->\r\n",
       "<g id=\"edge6\" class=\"edge\"><title>4&#45;&gt;9</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M325.48,-118.785C318.053,-105.817 309.452,-90.7962 301.6,-77.0844\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"304.575,-75.2362 296.568,-68.2976 298.5,-78.7148 304.575,-75.2362\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"327\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 10 -->\r\n",
       "<g id=\"node8\" class=\"node\"><title>10</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M426,-68C426,-68 355,-68 355,-68 349,-68 343,-62 343,-56 343,-56 343,-12 343,-12 343,-6 349,-0 355,-0 355,-0 426,-0 426,-0 432,-0 438,-6 438,-12 438,-12 438,-56 438,-56 438,-62 432,-68 426,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">10</text>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=91</text>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 87/4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=1.747</text>\r\n",
       "</g>\r\n",
       "<!-- 4&#45;&gt;10 -->\r\n",
       "<g id=\"edge7\" class=\"edge\"><title>4&#45;&gt;10</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M357.559,-118.785C362.56,-106.064 368.338,-91.3677 373.645,-77.8694\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"377.007,-78.8848 377.409,-68.2976 370.492,-76.3235 377.007,-78.8848\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"378.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 5 -->\r\n",
       "<g id=\"node10\" class=\"node\"><title>5</title>\r\n",
       "<path fill=\"#eb05f4\" stroke=\"black\" d=\"M581,-187C581,-187 470,-187 470,-187 464,-187 458,-181 458,-175 458,-175 458,-131 458,-131 458,-125 464,-119 470,-119 470,-119 581,-119 581,-119 587,-119 593,-125 593,-131 593,-131 593,-175 593,-175 593,-181 587,-187 581,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">5</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Fare &lt; 24.030</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 273</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;5 -->\r\n",
       "<g id=\"edge9\" class=\"edge\"><title>2&#45;&gt;5</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M525.5,-237.785C525.5,-225.311 525.5,-210.938 525.5,-197.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"529,-197.298 525.5,-187.298 522,-197.298 529,-197.298\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"537\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 6 -->\r\n",
       "<g id=\"node13\" class=\"node\"><title>6</title>\r\n",
       "<path fill=\"#eb05f4\" stroke=\"black\" d=\"M801,-187C801,-187 690,-187 690,-187 684,-187 678,-181 678,-175 678,-175 678,-131 678,-131 678,-125 684,-119 690,-119 690,-119 801,-119 801,-119 807,-119 813,-125 813,-131 813,-131 813,-175 813,-175 813,-181 807,-187 801,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Fare &lt; 24.030</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 178</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;6 -->\r\n",
       "<g id=\"edge12\" class=\"edge\"><title>2&#45;&gt;6</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M587.661,-237.942C614.605,-223.612 646.305,-206.754 674.199,-191.919\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"675.926,-194.965 683.111,-187.179 672.639,-188.785 675.926,-194.965\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"657.5\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 11 -->\r\n",
       "<g id=\"node11\" class=\"node\"><title>11</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M548.5,-68C548.5,-68 468.5,-68 468.5,-68 462.5,-68 456.5,-62 456.5,-56 456.5,-56 456.5,-12 456.5,-12 456.5,-6 462.5,-0 468.5,-0 468.5,-0 548.5,-0 548.5,-0 554.5,-0 560.5,-6 560.5,-12 560.5,-12 560.5,-56 560.5,-56 560.5,-62 554.5,-68 548.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">11</text>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=239</text>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 34/205</text>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;1.407</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;11 -->\r\n",
       "<g id=\"edge10\" class=\"edge\"><title>5&#45;&gt;11</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M520.674,-118.785C518.844,-106.188 516.732,-91.6529 514.786,-78.2629\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"518.24,-77.6904 513.338,-68.2976 511.312,-78.697 518.24,-77.6904\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"530\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 12 -->\r\n",
       "<g id=\"node12\" class=\"node\"><title>12</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M666,-68C666,-68 591,-68 591,-68 585,-68 579,-62 579,-56 579,-56 579,-12 579,-12 579,-6 585,-0 591,-0 591,-0 666,-0 666,-0 672,-0 678,-6 678,-12 678,-12 678,-56 678,-56 678,-62 672,-68 666,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">12</text>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=34</text>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 3/31</text>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;1.474</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;12 -->\r\n",
       "<g id=\"edge11\" class=\"edge\"><title>5&#45;&gt;12</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M554.74,-118.785C566.483,-105.447 580.137,-89.9362 592.483,-75.9124\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"595.206,-78.1162 599.187,-68.2976 589.952,-73.4908 595.206,-78.1162\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"591.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 13 -->\r\n",
       "<g id=\"node14\" class=\"node\"><title>13</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M783,-68C783,-68 708,-68 708,-68 702,-68 696,-62 696,-56 696,-56 696,-12 696,-12 696,-6 702,-0 708,-0 708,-0 783,-0 783,-0 789,-0 795,-6 795,-12 795,-12 795,-56 795,-56 795,-62 789,-68 783,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">13</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=57</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 6/51</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;1.475</text>\r\n",
       "</g>\r\n",
       "<!-- 6&#45;&gt;13 -->\r\n",
       "<g id=\"edge13\" class=\"edge\"><title>6&#45;&gt;13</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M745.5,-118.785C745.5,-106.311 745.5,-91.9377 745.5,-78.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"749,-78.2976 745.5,-68.2976 742,-78.2976 749,-78.2976\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"757\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 14 -->\r\n",
       "<g id=\"node15\" class=\"node\"><title>14</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M905.5,-68C905.5,-68 825.5,-68 825.5,-68 819.5,-68 813.5,-62 813.5,-56 813.5,-56 813.5,-12 813.5,-12 813.5,-6 819.5,-0 825.5,-0 825.5,-0 905.5,-0 905.5,-0 911.5,-0 917.5,-6 917.5,-12 917.5,-12 917.5,-56 917.5,-56 917.5,-62 911.5,-68 905.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"865.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">14</text>\r\n",
       "<text text-anchor=\"middle\" x=\"865.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=121</text>\r\n",
       "<text text-anchor=\"middle\" x=\"865.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 40/81</text>\r\n",
       "<text text-anchor=\"middle\" x=\"865.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.656</text>\r\n",
       "</g>\r\n",
       "<!-- 6&#45;&gt;14 -->\r\n",
       "<g id=\"edge14\" class=\"edge\"><title>6&#45;&gt;14</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M779.566,-118.785C793.374,-105.323 809.45,-89.6488 823.938,-75.5233\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"826.632,-77.7846 831.349,-68.2976 821.745,-72.7726 826.632,-77.7846\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"821.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "</g>\r\n",
       "</svg>\r\n"
      ],
      "text/plain": [
       "<graphviz.files.Source at 0x21f0ff9cf10>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>y</th>\n",
       "      <th>$p_0$</th>\n",
       "      <th>$l_0$</th>\n",
       "      <th>$r_0$</th>\n",
       "      <th>$\\gamma_0$</th>\n",
       "      <th>$l_1$</th>\n",
       "      <th>$p_1$</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-1.407407</td>\n",
       "      <td>-0.703704</td>\n",
       "      <td>0.330992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-1.407407</td>\n",
       "      <td>-0.703704</td>\n",
       "      <td>0.330992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>1.747368</td>\n",
       "      <td>0.873684</td>\n",
       "      <td>0.705512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-1.407407</td>\n",
       "      <td>-0.703704</td>\n",
       "      <td>0.330992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-0.656000</td>\n",
       "      <td>-0.328000</td>\n",
       "      <td>0.418727</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>663</th>\n",
       "      <td>0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-1.407407</td>\n",
       "      <td>-0.703704</td>\n",
       "      <td>0.330992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>664</th>\n",
       "      <td>1</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>-1.475410</td>\n",
       "      <td>-0.737705</td>\n",
       "      <td>0.323506</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>665</th>\n",
       "      <td>0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-0.656000</td>\n",
       "      <td>-0.328000</td>\n",
       "      <td>0.418727</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>666</th>\n",
       "      <td>0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-1.407407</td>\n",
       "      <td>-0.703704</td>\n",
       "      <td>0.330992</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>667</th>\n",
       "      <td>0</td>\n",
       "      <td>0.5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>-0.5</td>\n",
       "      <td>-1.407407</td>\n",
       "      <td>-0.703704</td>\n",
       "      <td>0.330992</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>668 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     y  $p_0$  $l_0$  $r_0$  $\\gamma_0$     $l_1$     $p_1$\n",
       "0    0    0.5    0.0   -0.5   -1.407407 -0.703704  0.330992\n",
       "1    0    0.5    0.0   -0.5   -1.407407 -0.703704  0.330992\n",
       "2    1    0.5    0.0    0.5    1.747368  0.873684  0.705512\n",
       "3    0    0.5    0.0   -0.5   -1.407407 -0.703704  0.330992\n",
       "4    0    0.5    0.0   -0.5   -0.656000 -0.328000  0.418727\n",
       "..  ..    ...    ...    ...         ...       ...       ...\n",
       "663  0    0.5    0.0   -0.5   -1.407407 -0.703704  0.330992\n",
       "664  1    0.5    0.0    0.5   -1.475410 -0.737705  0.323506\n",
       "665  0    0.5    0.0   -0.5   -0.656000 -0.328000  0.418727\n",
       "666  0    0.5    0.0   -0.5   -1.407407 -0.703704  0.330992\n",
       "667  0    0.5    0.0   -0.5   -1.407407 -0.703704  0.330992\n",
       "\n",
       "[668 rows x 7 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "iterate(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\r\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\r\n",
       "<!-- Generated by graphviz version 2.38.0 (20140413.2041)\r\n",
       " -->\r\n",
       "<!-- Title: Tree Pages: 1 -->\r\n",
       "<svg width=\"926pt\" height=\"433pt\"\r\n",
       " viewBox=\"0.00 0.00 926.00 433.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 429)\">\r\n",
       "<title>Tree</title>\r\n",
       "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-429 922,-429 922,4 -4,4\"/>\r\n",
       "<!-- 0 -->\r\n",
       "<g id=\"node1\" class=\"node\"><title>0</title>\r\n",
       "<path fill=\"#6c7115\" stroke=\"black\" d=\"M507,-425C507,-425 396,-425 396,-425 390,-425 384,-419 384,-413 384,-413 384,-369 384,-369 384,-363 390,-357 396,-357 396,-357 507,-357 507,-357 513,-357 519,-363 519,-369 519,-369 519,-413 519,-413 519,-419 513,-425 507,-425\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-409.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-394.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Sex &lt; 1.000</text>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-379.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-364.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 668</text>\r\n",
       "</g>\r\n",
       "<!-- 1 -->\r\n",
       "<g id=\"node2\" class=\"node\"><title>1</title>\r\n",
       "<path fill=\"#04b0f1\" stroke=\"black\" d=\"M401,-306C401,-306 290,-306 290,-306 284,-306 278,-300 278,-294 278,-294 278,-250 278,-250 278,-244 284,-238 290,-238 290,-238 401,-238 401,-238 407,-238 413,-244 413,-250 413,-250 413,-294 413,-294 413,-300 407,-306 401,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"345.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"345.5\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Pclass &lt; 0.243</text>\r\n",
       "<text text-anchor=\"middle\" x=\"345.5\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"345.5\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 217</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;1 -->\r\n",
       "<g id=\"edge1\" class=\"edge\"><title>0&#45;&gt;1</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M421.408,-356.785C409.324,-343.447 395.271,-327.936 382.566,-313.912\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"384.975,-311.359 375.667,-306.298 379.787,-316.058 384.975,-311.359\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"417\" y=\"-327.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 2 -->\r\n",
       "<g id=\"node9\" class=\"node\"><title>2</title>\r\n",
       "<path fill=\"#04b0f1\" stroke=\"black\" d=\"M581,-306C581,-306 470,-306 470,-306 464,-306 458,-300 458,-294 458,-294 458,-250 458,-250 458,-244 464,-238 470,-238 470,-238 581,-238 581,-238 587,-238 593,-244 593,-250 593,-250 593,-294 593,-294 593,-300 587,-306 581,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">2</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Pclass &lt; 0.243</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 451</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;2 -->\r\n",
       "<g id=\"edge8\" class=\"edge\"><title>0&#45;&gt;2</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M472.507,-356.785C480.71,-343.817 490.21,-328.796 498.882,-315.084\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"502.053,-316.62 504.44,-306.298 496.137,-312.878 502.053,-316.62\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"501.5\" y=\"-327.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 3 -->\r\n",
       "<g id=\"node3\" class=\"node\"><title>3</title>\r\n",
       "<path fill=\"#b0c48b\" stroke=\"black\" d=\"M220,-187C220,-187 109,-187 109,-187 103,-187 97,-181 97,-175 97,-175 97,-131 97,-131 97,-125 103,-119 109,-119 109,-119 220,-119 220,-119 226,-119 232,-125 232,-131 232,-131 232,-175 232,-175 232,-181 226,-187 220,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"164.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">3</text>\r\n",
       "<text text-anchor=\"middle\" x=\"164.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Embarked &lt; 0.390</text>\r\n",
       "<text text-anchor=\"middle\" x=\"164.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.8</text>\r\n",
       "<text text-anchor=\"middle\" x=\"164.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 100</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;3 -->\r\n",
       "<g id=\"edge2\" class=\"edge\"><title>1&#45;&gt;3</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M294.117,-237.785C272.338,-223.708 246.817,-207.21 224.207,-192.595\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"225.996,-189.584 215.698,-187.095 222.196,-195.463 225.996,-189.584\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"278\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 4 -->\r\n",
       "<g id=\"node6\" class=\"node\"><title>4</title>\r\n",
       "<path fill=\"#b0c48b\" stroke=\"black\" d=\"M401,-187C401,-187 290,-187 290,-187 284,-187 278,-181 278,-175 278,-175 278,-131 278,-131 278,-125 284,-119 290,-119 290,-119 401,-119 401,-119 407,-119 413,-125 413,-131 413,-131 413,-175 413,-175 413,-181 407,-187 401,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"345.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"345.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Embarked &lt; 0.390</text>\r\n",
       "<text text-anchor=\"middle\" x=\"345.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.8</text>\r\n",
       "<text text-anchor=\"middle\" x=\"345.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 117</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;4 -->\r\n",
       "<g id=\"edge5\" class=\"edge\"><title>1&#45;&gt;4</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M345.5,-237.785C345.5,-225.311 345.5,-210.938 345.5,-197.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"349,-197.298 345.5,-187.298 342,-197.298 349,-197.298\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"353.5\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 7 -->\r\n",
       "<g id=\"node4\" class=\"node\"><title>7</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M87,-68C87,-68 12,-68 12,-68 6,-68 0,-62 0,-56 0,-56 0,-12 0,-12 0,-6 6,-0 12,-0 12,-0 87,-0 87,-0 93,-0 99,-6 99,-12 99,-12 99,-56 99,-56 99,-62 93,-68 87,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"49.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">7</text>\r\n",
       "<text text-anchor=\"middle\" x=\"49.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=61</text>\r\n",
       "<text text-anchor=\"middle\" x=\"49.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 24/37</text>\r\n",
       "<text text-anchor=\"middle\" x=\"49.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.423</text>\r\n",
       "</g>\r\n",
       "<!-- 3&#45;&gt;7 -->\r\n",
       "<g id=\"edge3\" class=\"edge\"><title>3&#45;&gt;7</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M131.853,-118.785C118.621,-105.323 103.215,-89.6488 89.3305,-75.5233\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"91.7344,-72.9759 82.2284,-68.2976 86.7422,-77.8828 91.7344,-72.9759\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"126\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 8 -->\r\n",
       "<g id=\"node5\" class=\"node\"><title>8</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M200,-68C200,-68 129,-68 129,-68 123,-68 117,-62 117,-56 117,-56 117,-12 117,-12 117,-6 123,-0 129,-0 129,-0 200,-0 200,-0 206,-0 212,-6 212,-12 212,-12 212,-56 212,-56 212,-62 206,-68 200,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"164.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">8</text>\r\n",
       "<text text-anchor=\"middle\" x=\"164.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=39</text>\r\n",
       "<text text-anchor=\"middle\" x=\"164.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 30/9</text>\r\n",
       "<text text-anchor=\"middle\" x=\"164.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.783</text>\r\n",
       "</g>\r\n",
       "<!-- 3&#45;&gt;8 -->\r\n",
       "<g id=\"edge4\" class=\"edge\"><title>3&#45;&gt;8</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M164.5,-118.785C164.5,-106.311 164.5,-91.9377 164.5,-78.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"168,-78.2976 164.5,-68.2976 161,-78.2976 168,-78.2976\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"172.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 9 -->\r\n",
       "<g id=\"node7\" class=\"node\"><title>9</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M313,-68C313,-68 242,-68 242,-68 236,-68 230,-62 230,-56 230,-56 230,-12 230,-12 230,-6 236,-0 242,-0 242,-0 313,-0 313,-0 319,-0 325,-6 325,-12 325,-12 325,-56 325,-56 325,-62 319,-68 313,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">9</text>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=80</text>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 73/7</text>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.989</text>\r\n",
       "</g>\r\n",
       "<!-- 4&#45;&gt;9 -->\r\n",
       "<g id=\"edge6\" class=\"edge\"><title>4&#45;&gt;9</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M326.196,-118.785C318.659,-105.817 309.929,-90.7962 301.959,-77.0844\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"304.903,-75.1847 296.852,-68.2976 298.851,-78.7022 304.903,-75.1847\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"328\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 10 -->\r\n",
       "<g id=\"node8\" class=\"node\"><title>10</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M426,-68C426,-68 355,-68 355,-68 349,-68 343,-62 343,-56 343,-56 343,-12 343,-12 343,-6 349,-0 355,-0 355,-0 426,-0 426,-0 432,-0 438,-6 438,-12 438,-12 438,-56 438,-56 438,-62 432,-68 426,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">10</text>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=37</text>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 36/1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=1.156</text>\r\n",
       "</g>\r\n",
       "<!-- 4&#45;&gt;10 -->\r\n",
       "<g id=\"edge7\" class=\"edge\"><title>4&#45;&gt;10</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M358.275,-118.785C363.168,-106.064 368.82,-91.3677 374.012,-77.8694\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"377.37,-78.8875 377.693,-68.2976 370.837,-76.3746 377.37,-78.8875\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"379.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 5 -->\r\n",
       "<g id=\"node10\" class=\"node\"><title>5</title>\r\n",
       "<path fill=\"#b0c48b\" stroke=\"black\" d=\"M581,-187C581,-187 470,-187 470,-187 464,-187 458,-181 458,-175 458,-175 458,-131 458,-131 458,-125 464,-119 470,-119 470,-119 581,-119 581,-119 587,-119 593,-125 593,-131 593,-131 593,-175 593,-175 593,-181 587,-187 581,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">5</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Embarked &lt; 0.390</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.8</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 273</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;5 -->\r\n",
       "<g id=\"edge9\" class=\"edge\"><title>2&#45;&gt;5</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M525.5,-237.785C525.5,-225.311 525.5,-210.938 525.5,-197.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"529,-197.298 525.5,-187.298 522,-197.298 529,-197.298\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"537\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 6 -->\r\n",
       "<g id=\"node13\" class=\"node\"><title>6</title>\r\n",
       "<path fill=\"#b0c48b\" stroke=\"black\" d=\"M804,-187C804,-187 693,-187 693,-187 687,-187 681,-181 681,-175 681,-175 681,-131 681,-131 681,-125 687,-119 693,-119 693,-119 804,-119 804,-119 810,-119 816,-125 816,-131 816,-131 816,-175 816,-175 816,-181 810,-187 804,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"748.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"748.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Embarked &lt; 0.390</text>\r\n",
       "<text text-anchor=\"middle\" x=\"748.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.8</text>\r\n",
       "<text text-anchor=\"middle\" x=\"748.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 178</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;6 -->\r\n",
       "<g id=\"edge12\" class=\"edge\"><title>2&#45;&gt;6</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M588.509,-237.942C615.82,-223.612 647.952,-206.754 676.227,-191.919\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"678.031,-194.925 685.261,-187.179 674.779,-188.726 678.031,-194.925\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"658.5\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 11 -->\r\n",
       "<g id=\"node11\" class=\"node\"><title>11</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M548.5,-68C548.5,-68 468.5,-68 468.5,-68 462.5,-68 456.5,-62 456.5,-56 456.5,-56 456.5,-12 456.5,-12 456.5,-6 462.5,-0 468.5,-0 468.5,-0 548.5,-0 548.5,-0 554.5,-0 560.5,-6 560.5,-12 560.5,-12 560.5,-56 560.5,-56 560.5,-62 554.5,-68 548.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">11</text>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=209</text>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 26/183</text>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.910</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;11 -->\r\n",
       "<g id=\"edge10\" class=\"edge\"><title>5&#45;&gt;11</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M520.674,-118.785C518.844,-106.188 516.732,-91.6529 514.786,-78.2629\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"518.24,-77.6904 513.338,-68.2976 511.312,-78.697 518.24,-77.6904\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"530\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 12 -->\r\n",
       "<g id=\"node12\" class=\"node\"><title>12</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M666,-68C666,-68 591,-68 591,-68 585,-68 579,-62 579,-56 579,-56 579,-12 579,-12 579,-6 585,-0 591,-0 591,-0 666,-0 666,-0 672,-0 678,-6 678,-12 678,-12 678,-56 678,-56 678,-62 672,-68 666,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">12</text>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=64</text>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 11/53</text>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.669</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;12 -->\r\n",
       "<g id=\"edge11\" class=\"edge\"><title>5&#45;&gt;12</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M554.74,-118.785C566.483,-105.447 580.137,-89.9362 592.483,-75.9124\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"595.206,-78.1162 599.187,-68.2976 589.952,-73.4908 595.206,-78.1162\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"591.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 13 -->\r\n",
       "<g id=\"node14\" class=\"node\"><title>13</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M788.5,-68C788.5,-68 708.5,-68 708.5,-68 702.5,-68 696.5,-62 696.5,-56 696.5,-56 696.5,-12 696.5,-12 696.5,-6 702.5,-0 708.5,-0 708.5,-0 788.5,-0 788.5,-0 794.5,-0 800.5,-6 800.5,-12 800.5,-12 800.5,-56 800.5,-56 800.5,-62 794.5,-68 788.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"748.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">13</text>\r\n",
       "<text text-anchor=\"middle\" x=\"748.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=137</text>\r\n",
       "<text text-anchor=\"middle\" x=\"748.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 32/105</text>\r\n",
       "<text text-anchor=\"middle\" x=\"748.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.615</text>\r\n",
       "</g>\r\n",
       "<!-- 6&#45;&gt;13 -->\r\n",
       "<g id=\"edge13\" class=\"edge\"><title>6&#45;&gt;13</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M748.5,-118.785C748.5,-106.311 748.5,-91.9377 748.5,-78.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"752,-78.2976 748.5,-68.2976 745,-78.2976 752,-78.2976\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"760\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 14 -->\r\n",
       "<g id=\"node15\" class=\"node\"><title>14</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M906,-68C906,-68 831,-68 831,-68 825,-68 819,-62 819,-56 819,-56 819,-12 819,-12 819,-6 825,-0 831,-0 831,-0 906,-0 906,-0 912,-0 918,-6 918,-12 918,-12 918,-56 918,-56 918,-62 912,-68 906,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"868.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">14</text>\r\n",
       "<text text-anchor=\"middle\" x=\"868.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=41</text>\r\n",
       "<text text-anchor=\"middle\" x=\"868.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 14/27</text>\r\n",
       "<text text-anchor=\"middle\" x=\"868.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.256</text>\r\n",
       "</g>\r\n",
       "<!-- 6&#45;&gt;14 -->\r\n",
       "<g id=\"edge14\" class=\"edge\"><title>6&#45;&gt;14</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M782.566,-118.785C796.374,-105.323 812.45,-89.6488 826.938,-75.5233\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"829.632,-77.7846 834.349,-68.2976 824.745,-72.7726 829.632,-77.7846\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"824.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "</g>\r\n",
       "</svg>\r\n"
      ],
      "text/plain": [
       "<graphviz.files.Source at 0x21f74e6da60>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>y</th>\n",
       "      <th>$p_1$</th>\n",
       "      <th>$l_1$</th>\n",
       "      <th>$r_1$</th>\n",
       "      <th>$\\gamma_1$</th>\n",
       "      <th>$l_2$</th>\n",
       "      <th>$p_2$</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0.330992</td>\n",
       "      <td>-0.703704</td>\n",
       "      <td>-0.330992</td>\n",
       "      <td>-0.910258</td>\n",
       "      <td>-1.158833</td>\n",
       "      <td>0.238879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>0.330992</td>\n",
       "      <td>-0.703704</td>\n",
       "      <td>-0.330992</td>\n",
       "      <td>-0.910258</td>\n",
       "      <td>-1.158833</td>\n",
       "      <td>0.238879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0.705512</td>\n",
       "      <td>0.873684</td>\n",
       "      <td>0.294488</td>\n",
       "      <td>0.988512</td>\n",
       "      <td>1.367940</td>\n",
       "      <td>0.797047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>0.330992</td>\n",
       "      <td>-0.703704</td>\n",
       "      <td>-0.330992</td>\n",
       "      <td>-0.910258</td>\n",
       "      <td>-1.158833</td>\n",
       "      <td>0.238879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>0.418727</td>\n",
       "      <td>-0.328000</td>\n",
       "      <td>-0.418727</td>\n",
       "      <td>-0.614901</td>\n",
       "      <td>-0.635451</td>\n",
       "      <td>0.346276</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>663</th>\n",
       "      <td>0</td>\n",
       "      <td>0.330992</td>\n",
       "      <td>-0.703704</td>\n",
       "      <td>-0.330992</td>\n",
       "      <td>-0.910258</td>\n",
       "      <td>-1.158833</td>\n",
       "      <td>0.238879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>664</th>\n",
       "      <td>1</td>\n",
       "      <td>0.323506</td>\n",
       "      <td>-0.737705</td>\n",
       "      <td>0.676494</td>\n",
       "      <td>-0.256129</td>\n",
       "      <td>-0.865769</td>\n",
       "      <td>0.296135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>665</th>\n",
       "      <td>0</td>\n",
       "      <td>0.418727</td>\n",
       "      <td>-0.328000</td>\n",
       "      <td>-0.418727</td>\n",
       "      <td>-0.614901</td>\n",
       "      <td>-0.635451</td>\n",
       "      <td>0.346276</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>666</th>\n",
       "      <td>0</td>\n",
       "      <td>0.330992</td>\n",
       "      <td>-0.703704</td>\n",
       "      <td>-0.330992</td>\n",
       "      <td>-0.910258</td>\n",
       "      <td>-1.158833</td>\n",
       "      <td>0.238879</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>667</th>\n",
       "      <td>0</td>\n",
       "      <td>0.330992</td>\n",
       "      <td>-0.703704</td>\n",
       "      <td>-0.330992</td>\n",
       "      <td>-0.668986</td>\n",
       "      <td>-1.038197</td>\n",
       "      <td>0.261498</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>668 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     y     $p_1$     $l_1$     $r_1$  $\\gamma_1$     $l_2$     $p_2$\n",
       "0    0  0.330992 -0.703704 -0.330992   -0.910258 -1.158833  0.238879\n",
       "1    0  0.330992 -0.703704 -0.330992   -0.910258 -1.158833  0.238879\n",
       "2    1  0.705512  0.873684  0.294488    0.988512  1.367940  0.797047\n",
       "3    0  0.330992 -0.703704 -0.330992   -0.910258 -1.158833  0.238879\n",
       "4    0  0.418727 -0.328000 -0.418727   -0.614901 -0.635451  0.346276\n",
       "..  ..       ...       ...       ...         ...       ...       ...\n",
       "663  0  0.330992 -0.703704 -0.330992   -0.910258 -1.158833  0.238879\n",
       "664  1  0.323506 -0.737705  0.676494   -0.256129 -0.865769  0.296135\n",
       "665  0  0.418727 -0.328000 -0.418727   -0.614901 -0.635451  0.346276\n",
       "666  0  0.330992 -0.703704 -0.330992   -0.910258 -1.158833  0.238879\n",
       "667  0  0.330992 -0.703704 -0.330992   -0.668986 -1.038197  0.261498\n",
       "\n",
       "[668 rows x 7 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "iterate(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In iteration 1, we firstly train a tree using residuals_1. This tree tells us height is also important in determining weight. Whose who are less than 1.55 meters are supported to lose -7.289 and the other to gain 7.289. Again, we want to shrink this to 20%, which is -1.4578 and 1.4578. We then make prediction_2 based on prediction_1 and $\\gamma$. We see Alex gains 1.4578 kg because he is 1.6. Others also gain or lose weight because of the new rule."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\r\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\r\n",
       "<!-- Generated by graphviz version 2.38.0 (20140413.2041)\r\n",
       " -->\r\n",
       "<!-- Title: Tree Pages: 1 -->\r\n",
       "<svg width=\"918pt\" height=\"433pt\"\r\n",
       " viewBox=\"0.00 0.00 917.50 433.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 429)\">\r\n",
       "<title>Tree</title>\r\n",
       "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-429 913.5,-429 913.5,4 -4,4\"/>\r\n",
       "<!-- 0 -->\r\n",
       "<g id=\"node1\" class=\"node\"><title>0</title>\r\n",
       "<path fill=\"#6c7115\" stroke=\"black\" d=\"M512.5,-425C512.5,-425 401.5,-425 401.5,-425 395.5,-425 389.5,-419 389.5,-413 389.5,-413 389.5,-369 389.5,-369 389.5,-363 395.5,-357 401.5,-357 401.5,-357 512.5,-357 512.5,-357 518.5,-357 524.5,-363 524.5,-369 524.5,-369 524.5,-413 524.5,-413 524.5,-419 518.5,-425 512.5,-425\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"457\" y=\"-409.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"457\" y=\"-394.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Sex &lt; 1.000</text>\r\n",
       "<text text-anchor=\"middle\" x=\"457\" y=\"-379.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"457\" y=\"-364.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 668</text>\r\n",
       "</g>\r\n",
       "<!-- 1 -->\r\n",
       "<g id=\"node2\" class=\"node\"><title>1</title>\r\n",
       "<path fill=\"#04b0f1\" stroke=\"black\" d=\"M406.5,-306C406.5,-306 295.5,-306 295.5,-306 289.5,-306 283.5,-300 283.5,-294 283.5,-294 283.5,-250 283.5,-250 283.5,-244 289.5,-238 295.5,-238 295.5,-238 406.5,-238 406.5,-238 412.5,-238 418.5,-244 418.5,-250 418.5,-250 418.5,-294 418.5,-294 418.5,-300 412.5,-306 406.5,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"351\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"351\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Pclass &lt; 0.629</text>\r\n",
       "<text text-anchor=\"middle\" x=\"351\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.8</text>\r\n",
       "<text text-anchor=\"middle\" x=\"351\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 217</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;1 -->\r\n",
       "<g id=\"edge1\" class=\"edge\"><title>0&#45;&gt;1</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M426.908,-356.785C414.824,-343.447 400.771,-327.936 388.066,-313.912\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"390.475,-311.359 381.167,-306.298 385.287,-316.058 390.475,-311.359\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"422.5\" y=\"-327.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 2 -->\r\n",
       "<g id=\"node9\" class=\"node\"><title>2</title>\r\n",
       "<path fill=\"#04b0f1\" stroke=\"black\" d=\"M586.5,-306C586.5,-306 475.5,-306 475.5,-306 469.5,-306 463.5,-300 463.5,-294 463.5,-294 463.5,-250 463.5,-250 463.5,-244 469.5,-238 475.5,-238 475.5,-238 586.5,-238 586.5,-238 592.5,-238 598.5,-244 598.5,-250 598.5,-250 598.5,-294 598.5,-294 598.5,-300 592.5,-306 586.5,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"531\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">2</text>\r\n",
       "<text text-anchor=\"middle\" x=\"531\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Pclass &lt; 0.629</text>\r\n",
       "<text text-anchor=\"middle\" x=\"531\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.8</text>\r\n",
       "<text text-anchor=\"middle\" x=\"531\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 451</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;2 -->\r\n",
       "<g id=\"edge8\" class=\"edge\"><title>0&#45;&gt;2</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M478.007,-356.785C486.21,-343.817 495.71,-328.796 504.382,-315.084\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"507.553,-316.62 509.94,-306.298 501.637,-312.878 507.553,-316.62\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"507\" y=\"-327.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 3 -->\r\n",
       "<g id=\"node3\" class=\"node\"><title>3</title>\r\n",
       "<path fill=\"#d72203\" stroke=\"black\" d=\"M225.5,-187C225.5,-187 114.5,-187 114.5,-187 108.5,-187 102.5,-181 102.5,-175 102.5,-175 102.5,-131 102.5,-131 102.5,-125 108.5,-119 114.5,-119 114.5,-119 225.5,-119 225.5,-119 231.5,-119 237.5,-125 237.5,-131 237.5,-131 237.5,-175 237.5,-175 237.5,-181 231.5,-187 225.5,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"170\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">3</text>\r\n",
       "<text text-anchor=\"middle\" x=\"170\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Parch &lt; 0.550</text>\r\n",
       "<text text-anchor=\"middle\" x=\"170\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.9</text>\r\n",
       "<text text-anchor=\"middle\" x=\"170\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 148</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;3 -->\r\n",
       "<g id=\"edge2\" class=\"edge\"><title>1&#45;&gt;3</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M299.617,-237.785C277.838,-223.708 252.317,-207.21 229.707,-192.595\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"231.496,-189.584 221.198,-187.095 227.696,-195.463 231.496,-189.584\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"283.5\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 4 -->\r\n",
       "<g id=\"node6\" class=\"node\"><title>4</title>\r\n",
       "<path fill=\"#d72203\" stroke=\"black\" d=\"M406.5,-187C406.5,-187 295.5,-187 295.5,-187 289.5,-187 283.5,-181 283.5,-175 283.5,-175 283.5,-131 283.5,-131 283.5,-125 289.5,-119 295.5,-119 295.5,-119 406.5,-119 406.5,-119 412.5,-119 418.5,-125 418.5,-131 418.5,-131 418.5,-175 418.5,-175 418.5,-181 412.5,-187 406.5,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"351\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"351\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Parch &lt; 0.550</text>\r\n",
       "<text text-anchor=\"middle\" x=\"351\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.9</text>\r\n",
       "<text text-anchor=\"middle\" x=\"351\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 69</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;4 -->\r\n",
       "<g id=\"edge5\" class=\"edge\"><title>1&#45;&gt;4</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M351,-237.785C351,-225.311 351,-210.938 351,-197.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"354.5,-197.298 351,-187.298 347.5,-197.298 354.5,-197.298\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"359\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 7 -->\r\n",
       "<g id=\"node4\" class=\"node\"><title>7</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M92,-68C92,-68 12,-68 12,-68 6,-68 0,-62 0,-56 0,-56 0,-12 0,-12 0,-6 6,-0 12,-0 12,-0 92,-0 92,-0 98,-0 104,-6 104,-12 104,-12 104,-56 104,-56 104,-62 98,-68 92,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"52\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">7</text>\r\n",
       "<text text-anchor=\"middle\" x=\"52\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=112</text>\r\n",
       "<text text-anchor=\"middle\" x=\"52\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 70/42</text>\r\n",
       "<text text-anchor=\"middle\" x=\"52\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.112</text>\r\n",
       "</g>\r\n",
       "<!-- 3&#45;&gt;7 -->\r\n",
       "<g id=\"edge3\" class=\"edge\"><title>3&#45;&gt;7</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M136.502,-118.785C122.924,-105.323 107.116,-89.6488 92.8696,-75.5233\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"95.1476,-72.8531 85.5822,-68.2976 90.219,-77.8239 95.1476,-72.8531\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"130.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 8 -->\r\n",
       "<g id=\"node5\" class=\"node\"><title>8</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M205.5,-68C205.5,-68 134.5,-68 134.5,-68 128.5,-68 122.5,-62 122.5,-56 122.5,-56 122.5,-12 122.5,-12 122.5,-6 128.5,-0 134.5,-0 134.5,-0 205.5,-0 205.5,-0 211.5,-0 217.5,-6 217.5,-12 217.5,-12 217.5,-56 217.5,-56 217.5,-62 211.5,-68 205.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"170\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">8</text>\r\n",
       "<text text-anchor=\"middle\" x=\"170\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=36</text>\r\n",
       "<text text-anchor=\"middle\" x=\"170\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 27/9</text>\r\n",
       "<text text-anchor=\"middle\" x=\"170\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.496</text>\r\n",
       "</g>\r\n",
       "<!-- 3&#45;&gt;8 -->\r\n",
       "<g id=\"edge4\" class=\"edge\"><title>3&#45;&gt;8</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M170,-118.785C170,-106.311 170,-91.9377 170,-78.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"173.5,-78.2976 170,-68.2976 166.5,-78.2976 173.5,-78.2976\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"178\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 9 -->\r\n",
       "<g id=\"node7\" class=\"node\"><title>9</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M318.5,-68C318.5,-68 247.5,-68 247.5,-68 241.5,-68 235.5,-62 235.5,-56 235.5,-56 235.5,-12 235.5,-12 235.5,-6 241.5,-0 247.5,-0 247.5,-0 318.5,-0 318.5,-0 324.5,-0 330.5,-6 330.5,-12 330.5,-12 330.5,-56 330.5,-56 330.5,-62 324.5,-68 318.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"283\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">9</text>\r\n",
       "<text text-anchor=\"middle\" x=\"283\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=55</text>\r\n",
       "<text text-anchor=\"middle\" x=\"283\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 52/3</text>\r\n",
       "<text text-anchor=\"middle\" x=\"283\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.807</text>\r\n",
       "</g>\r\n",
       "<!-- 4&#45;&gt;9 -->\r\n",
       "<g id=\"edge6\" class=\"edge\"><title>4&#45;&gt;9</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M331.696,-118.785C324.159,-105.817 315.429,-90.7962 307.459,-77.0844\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"310.403,-75.1847 302.352,-68.2976 304.351,-78.7022 310.403,-75.1847\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"333.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 10 -->\r\n",
       "<g id=\"node8\" class=\"node\"><title>10</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M431.5,-68C431.5,-68 360.5,-68 360.5,-68 354.5,-68 348.5,-62 348.5,-56 348.5,-56 348.5,-12 348.5,-12 348.5,-6 354.5,-0 360.5,-0 360.5,-0 431.5,-0 431.5,-0 437.5,-0 443.5,-6 443.5,-12 443.5,-12 443.5,-56 443.5,-56 443.5,-62 437.5,-68 431.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"396\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">10</text>\r\n",
       "<text text-anchor=\"middle\" x=\"396\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=14</text>\r\n",
       "<text text-anchor=\"middle\" x=\"396\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 14/0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"396\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.859</text>\r\n",
       "</g>\r\n",
       "<!-- 4&#45;&gt;10 -->\r\n",
       "<g id=\"edge7\" class=\"edge\"><title>4&#45;&gt;10</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M363.775,-118.785C368.668,-106.064 374.32,-91.3677 379.512,-77.8694\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"382.87,-78.8875 383.193,-68.2976 376.337,-76.3746 382.87,-78.8875\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"385\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 5 -->\r\n",
       "<g id=\"node10\" class=\"node\"><title>5</title>\r\n",
       "<path fill=\"#d72203\" stroke=\"black\" d=\"M586.5,-187C586.5,-187 475.5,-187 475.5,-187 469.5,-187 463.5,-181 463.5,-175 463.5,-175 463.5,-131 463.5,-131 463.5,-125 469.5,-119 475.5,-119 475.5,-119 586.5,-119 586.5,-119 592.5,-119 598.5,-125 598.5,-131 598.5,-131 598.5,-175 598.5,-175 598.5,-181 592.5,-187 586.5,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"531\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">5</text>\r\n",
       "<text text-anchor=\"middle\" x=\"531\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Parch &lt; 0.550</text>\r\n",
       "<text text-anchor=\"middle\" x=\"531\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.9</text>\r\n",
       "<text text-anchor=\"middle\" x=\"531\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 354</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;5 -->\r\n",
       "<g id=\"edge9\" class=\"edge\"><title>2&#45;&gt;5</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M531,-237.785C531,-225.311 531,-210.938 531,-197.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"534.5,-197.298 531,-187.298 527.5,-197.298 534.5,-197.298\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"542.5\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 6 -->\r\n",
       "<g id=\"node13\" class=\"node\"><title>6</title>\r\n",
       "<path fill=\"#d72203\" stroke=\"black\" d=\"M800.5,-187C800.5,-187 689.5,-187 689.5,-187 683.5,-187 677.5,-181 677.5,-175 677.5,-175 677.5,-131 677.5,-131 677.5,-125 683.5,-119 689.5,-119 689.5,-119 800.5,-119 800.5,-119 806.5,-119 812.5,-125 812.5,-131 812.5,-131 812.5,-175 812.5,-175 812.5,-181 806.5,-187 800.5,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"745\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Parch &lt; 0.550</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.9</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 97</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;6 -->\r\n",
       "<g id=\"edge12\" class=\"edge\"><title>2&#45;&gt;6</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M591.466,-237.942C617.561,-223.674 648.243,-206.9 675.291,-192.112\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"677.218,-195.048 684.313,-187.179 673.86,-188.906 677.218,-195.048\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"659\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 11 -->\r\n",
       "<g id=\"node11\" class=\"node\"><title>11</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M554,-68C554,-68 474,-68 474,-68 468,-68 462,-62 462,-56 462,-56 462,-12 462,-12 462,-6 468,-0 474,-0 474,-0 554,-0 554,-0 560,-0 566,-6 566,-12 566,-12 566,-56 566,-56 566,-62 560,-68 554,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"514\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">11</text>\r\n",
       "<text text-anchor=\"middle\" x=\"514\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=319</text>\r\n",
       "<text text-anchor=\"middle\" x=\"514\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 37/282</text>\r\n",
       "<text text-anchor=\"middle\" x=\"514\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.719</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;11 -->\r\n",
       "<g id=\"edge10\" class=\"edge\"><title>5&#45;&gt;11</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M526.174,-118.785C524.344,-106.188 522.232,-91.6529 520.286,-78.2629\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"523.74,-77.6904 518.838,-68.2976 516.812,-78.697 523.74,-77.6904\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"535.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 12 -->\r\n",
       "<g id=\"node12\" class=\"node\"><title>12</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M667.5,-68C667.5,-68 596.5,-68 596.5,-68 590.5,-68 584.5,-62 584.5,-56 584.5,-56 584.5,-12 584.5,-12 584.5,-6 590.5,-0 596.5,-0 596.5,-0 667.5,-0 667.5,-0 673.5,-0 679.5,-6 679.5,-12 679.5,-12 679.5,-56 679.5,-56 679.5,-62 673.5,-68 667.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"632\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">12</text>\r\n",
       "<text text-anchor=\"middle\" x=\"632\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=35</text>\r\n",
       "<text text-anchor=\"middle\" x=\"632\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 11/24</text>\r\n",
       "<text text-anchor=\"middle\" x=\"632\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.215</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;12 -->\r\n",
       "<g id=\"edge11\" class=\"edge\"><title>5&#45;&gt;12</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M559.672,-118.785C571.187,-105.447 584.576,-89.9362 596.682,-75.9124\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"599.371,-78.1544 603.256,-68.2976 594.072,-73.5802 599.371,-78.1544\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"596\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 13 -->\r\n",
       "<g id=\"node14\" class=\"node\"><title>13</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M780.5,-68C780.5,-68 709.5,-68 709.5,-68 703.5,-68 697.5,-62 697.5,-56 697.5,-56 697.5,-12 697.5,-12 697.5,-6 703.5,-0 709.5,-0 709.5,-0 780.5,-0 780.5,-0 786.5,-0 792.5,-6 792.5,-12 792.5,-12 792.5,-56 792.5,-56 792.5,-62 786.5,-68 780.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"745\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">13</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=88</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 33/55</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.081</text>\r\n",
       "</g>\r\n",
       "<!-- 6&#45;&gt;13 -->\r\n",
       "<g id=\"edge13\" class=\"edge\"><title>6&#45;&gt;13</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M745,-118.785C745,-106.311 745,-91.9377 745,-78.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"748.5,-78.2976 745,-68.2976 741.5,-78.2976 748.5,-78.2976\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"756.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 14 -->\r\n",
       "<g id=\"node15\" class=\"node\"><title>14</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M897.5,-68C897.5,-68 822.5,-68 822.5,-68 816.5,-68 810.5,-62 810.5,-56 810.5,-56 810.5,-12 810.5,-12 810.5,-6 816.5,-0 822.5,-0 822.5,-0 897.5,-0 897.5,-0 903.5,-0 909.5,-6 909.5,-12 909.5,-12 909.5,-56 909.5,-56 909.5,-62 903.5,-68 897.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"860\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">14</text>\r\n",
       "<text text-anchor=\"middle\" x=\"860\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=9</text>\r\n",
       "<text text-anchor=\"middle\" x=\"860\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 2/7</text>\r\n",
       "<text text-anchor=\"middle\" x=\"860\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.416</text>\r\n",
       "</g>\r\n",
       "<!-- 6&#45;&gt;14 -->\r\n",
       "<g id=\"edge14\" class=\"edge\"><title>6&#45;&gt;14</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M777.647,-118.785C790.879,-105.323 806.285,-89.6488 820.169,-75.5233\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"822.758,-77.8828 827.272,-68.2976 817.766,-72.9759 822.758,-77.8828\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"818\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "</g>\r\n",
       "</svg>\r\n"
      ],
      "text/plain": [
       "<graphviz.files.Source at 0x21f0ff9cfa0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>y</th>\n",
       "      <th>$p_2$</th>\n",
       "      <th>$l_2$</th>\n",
       "      <th>$r_2$</th>\n",
       "      <th>$\\gamma_2$</th>\n",
       "      <th>$l_3$</th>\n",
       "      <th>$p_3$</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0.238879</td>\n",
       "      <td>-1.158833</td>\n",
       "      <td>-0.238879</td>\n",
       "      <td>-0.719013</td>\n",
       "      <td>-1.518339</td>\n",
       "      <td>0.179706</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>0.238879</td>\n",
       "      <td>-1.158833</td>\n",
       "      <td>-0.238879</td>\n",
       "      <td>-0.719013</td>\n",
       "      <td>-1.518339</td>\n",
       "      <td>0.179706</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0.797047</td>\n",
       "      <td>1.367940</td>\n",
       "      <td>0.202953</td>\n",
       "      <td>0.495575</td>\n",
       "      <td>1.615728</td>\n",
       "      <td>0.834205</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>0.238879</td>\n",
       "      <td>-1.158833</td>\n",
       "      <td>-0.238879</td>\n",
       "      <td>-0.719013</td>\n",
       "      <td>-1.518339</td>\n",
       "      <td>0.179706</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>0.346276</td>\n",
       "      <td>-0.635451</td>\n",
       "      <td>-0.346276</td>\n",
       "      <td>0.081061</td>\n",
       "      <td>-0.594920</td>\n",
       "      <td>0.355507</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>663</th>\n",
       "      <td>0</td>\n",
       "      <td>0.238879</td>\n",
       "      <td>-1.158833</td>\n",
       "      <td>-0.238879</td>\n",
       "      <td>-0.719013</td>\n",
       "      <td>-1.518339</td>\n",
       "      <td>0.179706</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>664</th>\n",
       "      <td>1</td>\n",
       "      <td>0.296135</td>\n",
       "      <td>-0.865769</td>\n",
       "      <td>0.703865</td>\n",
       "      <td>-0.719013</td>\n",
       "      <td>-1.225276</td>\n",
       "      <td>0.227009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>665</th>\n",
       "      <td>0</td>\n",
       "      <td>0.346276</td>\n",
       "      <td>-0.635451</td>\n",
       "      <td>-0.346276</td>\n",
       "      <td>0.081061</td>\n",
       "      <td>-0.594920</td>\n",
       "      <td>0.355507</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>666</th>\n",
       "      <td>0</td>\n",
       "      <td>0.238879</td>\n",
       "      <td>-1.158833</td>\n",
       "      <td>-0.238879</td>\n",
       "      <td>-0.719013</td>\n",
       "      <td>-1.518339</td>\n",
       "      <td>0.179706</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>667</th>\n",
       "      <td>0</td>\n",
       "      <td>0.261498</td>\n",
       "      <td>-1.038197</td>\n",
       "      <td>-0.261498</td>\n",
       "      <td>-0.719013</td>\n",
       "      <td>-1.397703</td>\n",
       "      <td>0.198181</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>668 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     y     $p_2$     $l_2$     $r_2$  $\\gamma_2$     $l_3$     $p_3$\n",
       "0    0  0.238879 -1.158833 -0.238879   -0.719013 -1.518339  0.179706\n",
       "1    0  0.238879 -1.158833 -0.238879   -0.719013 -1.518339  0.179706\n",
       "2    1  0.797047  1.367940  0.202953    0.495575  1.615728  0.834205\n",
       "3    0  0.238879 -1.158833 -0.238879   -0.719013 -1.518339  0.179706\n",
       "4    0  0.346276 -0.635451 -0.346276    0.081061 -0.594920  0.355507\n",
       "..  ..       ...       ...       ...         ...       ...       ...\n",
       "663  0  0.238879 -1.158833 -0.238879   -0.719013 -1.518339  0.179706\n",
       "664  1  0.296135 -0.865769  0.703865   -0.719013 -1.225276  0.227009\n",
       "665  0  0.346276 -0.635451 -0.346276    0.081061 -0.594920  0.355507\n",
       "666  0  0.238879 -1.158833 -0.238879   -0.719013 -1.518339  0.179706\n",
       "667  0  0.261498 -1.038197 -0.261498   -0.719013 -1.397703  0.198181\n",
       "\n",
       "[668 rows x 7 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "iterate(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Iteration 2 again tells us that gender matters."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\r\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\r\n",
       "<!-- Generated by graphviz version 2.38.0 (20140413.2041)\r\n",
       " -->\r\n",
       "<!-- Title: Tree Pages: 1 -->\r\n",
       "<svg width=\"926pt\" height=\"433pt\"\r\n",
       " viewBox=\"0.00 0.00 925.50 433.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 429)\">\r\n",
       "<title>Tree</title>\r\n",
       "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-429 921.5,-429 921.5,4 -4,4\"/>\r\n",
       "<!-- 0 -->\r\n",
       "<g id=\"node1\" class=\"node\"><title>0</title>\r\n",
       "<path fill=\"#6c7115\" stroke=\"black\" d=\"M507,-425C507,-425 396,-425 396,-425 390,-425 384,-419 384,-413 384,-413 384,-369 384,-369 384,-363 390,-357 396,-357 396,-357 507,-357 507,-357 513,-357 519,-363 519,-369 519,-369 519,-413 519,-413 519,-419 513,-425 507,-425\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-409.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-394.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Sex &lt; 1.000</text>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-379.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"451.5\" y=\"-364.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 668</text>\r\n",
       "</g>\r\n",
       "<!-- 1 -->\r\n",
       "<g id=\"node2\" class=\"node\"><title>1</title>\r\n",
       "<path fill=\"#04b0f1\" stroke=\"black\" d=\"M400,-306C400,-306 289,-306 289,-306 283,-306 277,-300 277,-294 277,-294 277,-250 277,-250 277,-244 283,-238 289,-238 289,-238 400,-238 400,-238 406,-238 412,-244 412,-250 412,-250 412,-294 412,-294 412,-300 406,-306 400,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Pclass &lt; 0.243</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 217</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;1 -->\r\n",
       "<g id=\"edge1\" class=\"edge\"><title>0&#45;&gt;1</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M421.124,-356.785C408.926,-343.447 394.741,-327.936 381.916,-313.912\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"384.283,-311.315 374.952,-306.298 379.118,-316.039 384.283,-311.315\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"416\" y=\"-327.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 2 -->\r\n",
       "<g id=\"node9\" class=\"node\"><title>2</title>\r\n",
       "<path fill=\"#04b0f1\" stroke=\"black\" d=\"M581,-306C581,-306 470,-306 470,-306 464,-306 458,-300 458,-294 458,-294 458,-250 458,-250 458,-244 464,-238 470,-238 470,-238 581,-238 581,-238 587,-238 593,-244 593,-250 593,-250 593,-294 593,-294 593,-300 587,-306 581,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">2</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Pclass &lt; 0.243</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 451</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;2 -->\r\n",
       "<g id=\"edge8\" class=\"edge\"><title>0&#45;&gt;2</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M472.507,-356.785C480.71,-343.817 490.21,-328.796 498.882,-315.084\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"502.053,-316.62 504.44,-306.298 496.137,-312.878 502.053,-316.62\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"501.5\" y=\"-327.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 3 -->\r\n",
       "<g id=\"node3\" class=\"node\"><title>3</title>\r\n",
       "<path fill=\"#eb05f4\" stroke=\"black\" d=\"M218,-187C218,-187 107,-187 107,-187 101,-187 95,-181 95,-175 95,-175 95,-131 95,-131 95,-125 101,-119 107,-119 107,-119 218,-119 218,-119 224,-119 230,-125 230,-131 230,-131 230,-175 230,-175 230,-181 224,-187 218,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">3</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Fare &lt; 24.030</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 100</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;3 -->\r\n",
       "<g id=\"edge2\" class=\"edge\"><title>1&#45;&gt;3</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M292.833,-237.785C270.934,-223.708 245.272,-207.21 222.537,-192.595\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"224.286,-189.558 213.981,-187.095 220.5,-195.447 224.286,-189.558\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"276\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 4 -->\r\n",
       "<g id=\"node6\" class=\"node\"><title>4</title>\r\n",
       "<path fill=\"#eb05f4\" stroke=\"black\" d=\"M400,-187C400,-187 289,-187 289,-187 283,-187 277,-181 277,-175 277,-175 277,-131 277,-131 277,-125 283,-119 289,-119 289,-119 400,-119 400,-119 406,-119 412,-125 412,-131 412,-131 412,-175 412,-175 412,-181 406,-187 400,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Fare &lt; 24.030</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"344.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 117</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;4 -->\r\n",
       "<g id=\"edge5\" class=\"edge\"><title>1&#45;&gt;4</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M344.5,-237.785C344.5,-225.311 344.5,-210.938 344.5,-197.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"348,-197.298 344.5,-187.298 341,-197.298 348,-197.298\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"352.5\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 7 -->\r\n",
       "<g id=\"node4\" class=\"node\"><title>7</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M83,-68C83,-68 12,-68 12,-68 6,-68 0,-62 0,-56 0,-56 0,-12 0,-12 0,-6 6,-0 12,-0 12,-0 83,-0 83,-0 89,-0 95,-6 95,-12 95,-12 95,-56 95,-56 95,-62 89,-68 83,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">7</text>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=79</text>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 51/28</text>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.155</text>\r\n",
       "</g>\r\n",
       "<!-- 3&#45;&gt;7 -->\r\n",
       "<g id=\"edge3\" class=\"edge\"><title>3&#45;&gt;7</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M129.853,-118.785C116.621,-105.323 101.215,-89.6488 87.3305,-75.5233\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"89.7344,-72.9759 80.2284,-68.2976 84.7422,-77.8828 89.7344,-72.9759\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"124\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 8 -->\r\n",
       "<g id=\"node5\" class=\"node\"><title>8</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M200,-68C200,-68 125,-68 125,-68 119,-68 113,-62 113,-56 113,-56 113,-12 113,-12 113,-6 119,-0 125,-0 125,-0 200,-0 200,-0 206,-0 212,-6 212,-12 212,-12 212,-56 212,-56 212,-62 206,-68 200,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">8</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=21</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 3/18</text>\r\n",
       "<text text-anchor=\"middle\" x=\"162.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.733</text>\r\n",
       "</g>\r\n",
       "<!-- 3&#45;&gt;8 -->\r\n",
       "<g id=\"edge4\" class=\"edge\"><title>3&#45;&gt;8</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M162.5,-118.785C162.5,-106.311 162.5,-91.9377 162.5,-78.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"166,-78.2976 162.5,-68.2976 159,-78.2976 166,-78.2976\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"170.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 9 -->\r\n",
       "<g id=\"node7\" class=\"node\"><title>9</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M313,-68C313,-68 242,-68 242,-68 236,-68 230,-62 230,-56 230,-56 230,-12 230,-12 230,-6 236,-0 242,-0 242,-0 313,-0 313,-0 319,-0 325,-6 325,-12 325,-12 325,-56 325,-56 325,-62 319,-68 313,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">9</text>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=26</text>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 22/4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"277.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.365</text>\r\n",
       "</g>\r\n",
       "<!-- 4&#45;&gt;9 -->\r\n",
       "<g id=\"edge6\" class=\"edge\"><title>4&#45;&gt;9</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M325.48,-118.785C318.053,-105.817 309.452,-90.7962 301.6,-77.0844\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"304.575,-75.2362 296.568,-68.2976 298.5,-78.7148 304.575,-75.2362\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"327\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 10 -->\r\n",
       "<g id=\"node8\" class=\"node\"><title>10</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M426,-68C426,-68 355,-68 355,-68 349,-68 343,-62 343,-56 343,-56 343,-12 343,-12 343,-6 349,-0 355,-0 355,-0 426,-0 426,-0 432,-0 438,-6 438,-12 438,-12 438,-56 438,-56 438,-62 432,-68 426,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">10</text>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=91</text>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 87/4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"390.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.767</text>\r\n",
       "</g>\r\n",
       "<!-- 4&#45;&gt;10 -->\r\n",
       "<g id=\"edge7\" class=\"edge\"><title>4&#45;&gt;10</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M357.559,-118.785C362.56,-106.064 368.338,-91.3677 373.645,-77.8694\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"377.007,-78.8848 377.409,-68.2976 370.492,-76.3235 377.007,-78.8848\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"378.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 5 -->\r\n",
       "<g id=\"node10\" class=\"node\"><title>5</title>\r\n",
       "<path fill=\"#eb05f4\" stroke=\"black\" d=\"M581,-187C581,-187 470,-187 470,-187 464,-187 458,-181 458,-175 458,-175 458,-131 458,-131 458,-125 464,-119 470,-119 470,-119 581,-119 581,-119 587,-119 593,-125 593,-131 593,-131 593,-175 593,-175 593,-181 587,-187 581,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">5</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Fare &lt; 24.030</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"525.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 273</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;5 -->\r\n",
       "<g id=\"edge9\" class=\"edge\"><title>2&#45;&gt;5</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M525.5,-237.785C525.5,-225.311 525.5,-210.938 525.5,-197.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"529,-197.298 525.5,-187.298 522,-197.298 529,-197.298\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"537\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 6 -->\r\n",
       "<g id=\"node13\" class=\"node\"><title>6</title>\r\n",
       "<path fill=\"#eb05f4\" stroke=\"black\" d=\"M801,-187C801,-187 690,-187 690,-187 684,-187 678,-181 678,-175 678,-175 678,-131 678,-131 678,-125 684,-119 690,-119 690,-119 801,-119 801,-119 807,-119 813,-125 813,-131 813,-131 813,-175 813,-175 813,-181 807,-187 801,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Fare &lt; 24.030</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 178</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;6 -->\r\n",
       "<g id=\"edge12\" class=\"edge\"><title>2&#45;&gt;6</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M587.661,-237.942C614.605,-223.612 646.305,-206.754 674.199,-191.919\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"675.926,-194.965 683.111,-187.179 672.639,-188.785 675.926,-194.965\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"657.5\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 11 -->\r\n",
       "<g id=\"node11\" class=\"node\"><title>11</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M548.5,-68C548.5,-68 468.5,-68 468.5,-68 462.5,-68 456.5,-62 456.5,-56 456.5,-56 456.5,-12 456.5,-12 456.5,-6 462.5,-0 468.5,-0 468.5,-0 548.5,-0 548.5,-0 554.5,-0 560.5,-6 560.5,-12 560.5,-12 560.5,-56 560.5,-56 560.5,-62 554.5,-68 548.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">11</text>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=239</text>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 34/205</text>\r\n",
       "<text text-anchor=\"middle\" x=\"508.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.297</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;11 -->\r\n",
       "<g id=\"edge10\" class=\"edge\"><title>5&#45;&gt;11</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M520.674,-118.785C518.844,-106.188 516.732,-91.6529 514.786,-78.2629\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"518.24,-77.6904 513.338,-68.2976 511.312,-78.697 518.24,-77.6904\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"530\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 12 -->\r\n",
       "<g id=\"node12\" class=\"node\"><title>12</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M666,-68C666,-68 591,-68 591,-68 585,-68 579,-62 579,-56 579,-56 579,-12 579,-12 579,-6 585,-0 591,-0 591,-0 666,-0 666,-0 672,-0 678,-6 678,-12 678,-12 678,-56 678,-56 678,-62 672,-68 666,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">12</text>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=34</text>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 3/31</text>\r\n",
       "<text text-anchor=\"middle\" x=\"628.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.616</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;12 -->\r\n",
       "<g id=\"edge11\" class=\"edge\"><title>5&#45;&gt;12</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M554.74,-118.785C566.483,-105.447 580.137,-89.9362 592.483,-75.9124\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"595.206,-78.1162 599.187,-68.2976 589.952,-73.4908 595.206,-78.1162\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"591.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 13 -->\r\n",
       "<g id=\"node14\" class=\"node\"><title>13</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M783,-68C783,-68 708,-68 708,-68 702,-68 696,-62 696,-56 696,-56 696,-12 696,-12 696,-6 702,-0 708,-0 708,-0 783,-0 783,-0 789,-0 795,-6 795,-12 795,-12 795,-56 795,-56 795,-62 789,-68 783,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">13</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=57</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 6/51</text>\r\n",
       "<text text-anchor=\"middle\" x=\"745.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.567</text>\r\n",
       "</g>\r\n",
       "<!-- 6&#45;&gt;13 -->\r\n",
       "<g id=\"edge13\" class=\"edge\"><title>6&#45;&gt;13</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M745.5,-118.785C745.5,-106.311 745.5,-91.9377 745.5,-78.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"749,-78.2976 745.5,-68.2976 742,-78.2976 749,-78.2976\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"757\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 14 -->\r\n",
       "<g id=\"node15\" class=\"node\"><title>14</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M905.5,-68C905.5,-68 825.5,-68 825.5,-68 819.5,-68 813.5,-62 813.5,-56 813.5,-56 813.5,-12 813.5,-12 813.5,-6 819.5,-0 825.5,-0 825.5,-0 905.5,-0 905.5,-0 911.5,-0 917.5,-6 917.5,-12 917.5,-12 917.5,-56 917.5,-56 917.5,-62 911.5,-68 905.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"865.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">14</text>\r\n",
       "<text text-anchor=\"middle\" x=\"865.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=121</text>\r\n",
       "<text text-anchor=\"middle\" x=\"865.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 40/81</text>\r\n",
       "<text text-anchor=\"middle\" x=\"865.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.081</text>\r\n",
       "</g>\r\n",
       "<!-- 6&#45;&gt;14 -->\r\n",
       "<g id=\"edge14\" class=\"edge\"><title>6&#45;&gt;14</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M779.566,-118.785C793.374,-105.323 809.45,-89.6488 823.938,-75.5233\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"826.632,-77.7846 831.349,-68.2976 821.745,-72.7726 826.632,-77.7846\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"821.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "</g>\r\n",
       "</svg>\r\n"
      ],
      "text/plain": [
       "<graphviz.files.Source at 0x21f0e7e5700>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>y</th>\n",
       "      <th>$p_3$</th>\n",
       "      <th>$l_3$</th>\n",
       "      <th>$r_3$</th>\n",
       "      <th>$\\gamma_3$</th>\n",
       "      <th>$l_4$</th>\n",
       "      <th>$p_4$</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0.179706</td>\n",
       "      <td>-1.518339</td>\n",
       "      <td>-0.179706</td>\n",
       "      <td>-0.297403</td>\n",
       "      <td>-1.667041</td>\n",
       "      <td>0.158819</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>0.179706</td>\n",
       "      <td>-1.518339</td>\n",
       "      <td>-0.179706</td>\n",
       "      <td>-0.297403</td>\n",
       "      <td>-1.667041</td>\n",
       "      <td>0.158819</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0.834205</td>\n",
       "      <td>1.615728</td>\n",
       "      <td>0.165795</td>\n",
       "      <td>0.767324</td>\n",
       "      <td>1.999390</td>\n",
       "      <td>0.880733</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>0.179706</td>\n",
       "      <td>-1.518339</td>\n",
       "      <td>-0.179706</td>\n",
       "      <td>-0.297403</td>\n",
       "      <td>-1.667041</td>\n",
       "      <td>0.158819</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>0.355507</td>\n",
       "      <td>-0.594920</td>\n",
       "      <td>-0.355507</td>\n",
       "      <td>-0.080759</td>\n",
       "      <td>-0.635300</td>\n",
       "      <td>0.346310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>663</th>\n",
       "      <td>0</td>\n",
       "      <td>0.179706</td>\n",
       "      <td>-1.518339</td>\n",
       "      <td>-0.179706</td>\n",
       "      <td>-0.297403</td>\n",
       "      <td>-1.667041</td>\n",
       "      <td>0.158819</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>664</th>\n",
       "      <td>1</td>\n",
       "      <td>0.227009</td>\n",
       "      <td>-1.225276</td>\n",
       "      <td>0.772991</td>\n",
       "      <td>-0.566894</td>\n",
       "      <td>-1.508723</td>\n",
       "      <td>0.181128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>665</th>\n",
       "      <td>0</td>\n",
       "      <td>0.355507</td>\n",
       "      <td>-0.594920</td>\n",
       "      <td>-0.355507</td>\n",
       "      <td>-0.080759</td>\n",
       "      <td>-0.635300</td>\n",
       "      <td>0.346310</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>666</th>\n",
       "      <td>0</td>\n",
       "      <td>0.179706</td>\n",
       "      <td>-1.518339</td>\n",
       "      <td>-0.179706</td>\n",
       "      <td>-0.297403</td>\n",
       "      <td>-1.667041</td>\n",
       "      <td>0.158819</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>667</th>\n",
       "      <td>0</td>\n",
       "      <td>0.198181</td>\n",
       "      <td>-1.397703</td>\n",
       "      <td>-0.198181</td>\n",
       "      <td>-0.297403</td>\n",
       "      <td>-1.546405</td>\n",
       "      <td>0.175606</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>668 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     y     $p_3$     $l_3$     $r_3$  $\\gamma_3$     $l_4$     $p_4$\n",
       "0    0  0.179706 -1.518339 -0.179706   -0.297403 -1.667041  0.158819\n",
       "1    0  0.179706 -1.518339 -0.179706   -0.297403 -1.667041  0.158819\n",
       "2    1  0.834205  1.615728  0.165795    0.767324  1.999390  0.880733\n",
       "3    0  0.179706 -1.518339 -0.179706   -0.297403 -1.667041  0.158819\n",
       "4    0  0.355507 -0.594920 -0.355507   -0.080759 -0.635300  0.346310\n",
       "..  ..       ...       ...       ...         ...       ...       ...\n",
       "663  0  0.179706 -1.518339 -0.179706   -0.297403 -1.667041  0.158819\n",
       "664  1  0.227009 -1.225276  0.772991   -0.566894 -1.508723  0.181128\n",
       "665  0  0.355507 -0.594920 -0.355507   -0.080759 -0.635300  0.346310\n",
       "666  0  0.179706 -1.518339 -0.179706   -0.297403 -1.667041  0.158819\n",
       "667  0  0.198181 -1.397703 -0.198181   -0.297403 -1.546405  0.175606\n",
       "\n",
       "[668 rows x 7 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "iterate(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\r\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\r\n",
       "<!-- Generated by graphviz version 2.38.0 (20140413.2041)\r\n",
       " -->\r\n",
       "<!-- Title: Tree Pages: 1 -->\r\n",
       "<svg width=\"908pt\" height=\"433pt\"\r\n",
       " viewBox=\"0.00 0.00 908.00 433.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\r\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 429)\">\r\n",
       "<title>Tree</title>\r\n",
       "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-429 904,-429 904,4 -4,4\"/>\r\n",
       "<!-- 0 -->\r\n",
       "<g id=\"node1\" class=\"node\"><title>0</title>\r\n",
       "<path fill=\"#b0c48b\" stroke=\"black\" d=\"M528,-425C528,-425 417,-425 417,-425 411,-425 405,-419 405,-413 405,-413 405,-369 405,-369 405,-363 411,-357 417,-357 417,-357 528,-357 528,-357 534,-357 540,-363 540,-369 540,-369 540,-413 540,-413 540,-419 534,-425 528,-425\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"472.5\" y=\"-409.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"472.5\" y=\"-394.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Embarked &lt; 0.553</text>\r\n",
       "<text text-anchor=\"middle\" x=\"472.5\" y=\"-379.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.9</text>\r\n",
       "<text text-anchor=\"middle\" x=\"472.5\" y=\"-364.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 668</text>\r\n",
       "</g>\r\n",
       "<!-- 1 -->\r\n",
       "<g id=\"node2\" class=\"node\"><title>1</title>\r\n",
       "<path fill=\"#d72203\" stroke=\"black\" d=\"M425,-306C425,-306 314,-306 314,-306 308,-306 302,-300 302,-294 302,-294 302,-250 302,-250 302,-244 308,-238 314,-238 314,-238 425,-238 425,-238 431,-238 437,-244 437,-250 437,-250 437,-294 437,-294 437,-300 431,-306 425,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"369.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"369.5\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Parch &lt; 0.344</text>\r\n",
       "<text text-anchor=\"middle\" x=\"369.5\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"369.5\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 546</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;1 -->\r\n",
       "<g id=\"edge1\" class=\"edge\"><title>0&#45;&gt;1</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M443.26,-356.785C431.517,-343.447 417.863,-327.936 405.517,-313.912\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"408.048,-311.491 398.813,-306.298 402.794,-316.116 408.048,-311.491\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"439\" y=\"-327.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 2 -->\r\n",
       "<g id=\"node9\" class=\"node\"><title>2</title>\r\n",
       "<path fill=\"#d72203\" stroke=\"black\" d=\"M599,-306C599,-306 488,-306 488,-306 482,-306 476,-300 476,-294 476,-294 476,-250 476,-250 476,-244 482,-238 488,-238 488,-238 599,-238 599,-238 605,-238 611,-244 611,-250 611,-250 611,-294 611,-294 611,-300 605,-306 599,-306\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"543.5\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">2</text>\r\n",
       "<text text-anchor=\"middle\" x=\"543.5\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Parch &lt; 0.344</text>\r\n",
       "<text text-anchor=\"middle\" x=\"543.5\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"543.5\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 122</text>\r\n",
       "</g>\r\n",
       "<!-- 0&#45;&gt;2 -->\r\n",
       "<g id=\"edge8\" class=\"edge\"><title>0&#45;&gt;2</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M492.656,-356.785C500.525,-343.817 509.641,-328.796 517.962,-315.084\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"521.098,-316.662 523.294,-306.298 515.114,-313.031 521.098,-316.662\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"520.5\" y=\"-327.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 3 -->\r\n",
       "<g id=\"node3\" class=\"node\"><title>3</title>\r\n",
       "<path fill=\"#e96b4c\" stroke=\"black\" d=\"M221,-187C221,-187 110,-187 110,-187 104,-187 98,-181 98,-175 98,-175 98,-131 98,-131 98,-125 104,-119 110,-119 110,-119 221,-119 221,-119 227,-119 233,-125 233,-131 233,-131 233,-175 233,-175 233,-181 227,-187 221,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"165.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">3</text>\r\n",
       "<text text-anchor=\"middle\" x=\"165.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">SibSp &lt; 0.345</text>\r\n",
       "<text text-anchor=\"middle\" x=\"165.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"165.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 422</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;3 -->\r\n",
       "<g id=\"edge2\" class=\"edge\"><title>1&#45;&gt;3</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M311.86,-237.942C287.092,-223.736 257.99,-207.046 232.288,-192.305\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"233.767,-189.119 223.351,-187.179 230.285,-195.191 233.767,-189.119\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"292\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 4 -->\r\n",
       "<g id=\"node6\" class=\"node\"><title>4</title>\r\n",
       "<path fill=\"#e96b4c\" stroke=\"black\" d=\"M425,-187C425,-187 314,-187 314,-187 308,-187 302,-181 302,-175 302,-175 302,-131 302,-131 302,-125 308,-119 314,-119 314,-119 425,-119 425,-119 431,-119 437,-125 437,-131 437,-131 437,-175 437,-175 437,-181 431,-187 425,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"369.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">4</text>\r\n",
       "<text text-anchor=\"middle\" x=\"369.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">SibSp &lt; 0.345</text>\r\n",
       "<text text-anchor=\"middle\" x=\"369.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"369.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 124</text>\r\n",
       "</g>\r\n",
       "<!-- 1&#45;&gt;4 -->\r\n",
       "<g id=\"edge5\" class=\"edge\"><title>1&#45;&gt;4</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M369.5,-237.785C369.5,-225.311 369.5,-210.938 369.5,-197.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"373,-197.298 369.5,-187.298 366,-197.298 373,-197.298\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"377.5\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 7 -->\r\n",
       "<g id=\"node4\" class=\"node\"><title>7</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M83,-68C83,-68 12,-68 12,-68 6,-68 0,-62 0,-56 0,-56 0,-12 0,-12 0,-6 6,-0 12,-0 12,-0 83,-0 83,-0 89,-0 95,-6 95,-12 95,-12 95,-56 95,-56 95,-62 89,-68 83,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">7</text>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 1/0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"47.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.179</text>\r\n",
       "</g>\r\n",
       "<!-- 3&#45;&gt;7 -->\r\n",
       "<g id=\"edge3\" class=\"edge\"><title>3&#45;&gt;7</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M132.002,-118.785C118.424,-105.323 102.616,-89.6488 88.3696,-75.5233\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"90.6476,-72.8531 81.0822,-68.2976 85.719,-77.8239 90.6476,-72.8531\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"126\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 8 -->\r\n",
       "<g id=\"node5\" class=\"node\"><title>8</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M205.5,-68C205.5,-68 125.5,-68 125.5,-68 119.5,-68 113.5,-62 113.5,-56 113.5,-56 113.5,-12 113.5,-12 113.5,-6 119.5,-0 125.5,-0 125.5,-0 205.5,-0 205.5,-0 211.5,-0 217.5,-6 217.5,-12 217.5,-12 217.5,-56 217.5,-56 217.5,-62 211.5,-68 205.5,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"165.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">8</text>\r\n",
       "<text text-anchor=\"middle\" x=\"165.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=421</text>\r\n",
       "<text text-anchor=\"middle\" x=\"165.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 114/307</text>\r\n",
       "<text text-anchor=\"middle\" x=\"165.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.273</text>\r\n",
       "</g>\r\n",
       "<!-- 3&#45;&gt;8 -->\r\n",
       "<g id=\"edge4\" class=\"edge\"><title>3&#45;&gt;8</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M165.5,-118.785C165.5,-106.311 165.5,-91.9377 165.5,-78.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"169,-78.2976 165.5,-68.2976 162,-78.2976 169,-78.2976\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"173.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 9 -->\r\n",
       "<g id=\"node7\" class=\"node\"><title>9</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M323,-68C323,-68 248,-68 248,-68 242,-68 236,-62 236,-56 236,-56 236,-12 236,-12 236,-6 242,-0 248,-0 248,-0 323,-0 323,-0 329,-0 335,-6 335,-12 335,-12 335,-56 335,-56 335,-62 329,-68 323,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"285.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">9</text>\r\n",
       "<text text-anchor=\"middle\" x=\"285.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=39</text>\r\n",
       "<text text-anchor=\"middle\" x=\"285.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 5/34</text>\r\n",
       "<text text-anchor=\"middle\" x=\"285.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=&#45;0.692</text>\r\n",
       "</g>\r\n",
       "<!-- 4&#45;&gt;9 -->\r\n",
       "<g id=\"edge6\" class=\"edge\"><title>4&#45;&gt;9</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M345.654,-118.785C336.254,-105.694 325.353,-90.5099 315.433,-76.693\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"318.081,-74.3796 309.406,-68.2976 312.395,-78.4621 318.081,-74.3796\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"345\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 10 -->\r\n",
       "<g id=\"node8\" class=\"node\"><title>10</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M436,-68C436,-68 365,-68 365,-68 359,-68 353,-62 353,-56 353,-56 353,-12 353,-12 353,-6 359,-0 365,-0 365,-0 436,-0 436,-0 442,-0 448,-6 448,-12 448,-12 448,-56 448,-56 448,-62 442,-68 436,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"400.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">10</text>\r\n",
       "<text text-anchor=\"middle\" x=\"400.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=85</text>\r\n",
       "<text text-anchor=\"middle\" x=\"400.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 56/29</text>\r\n",
       "<text text-anchor=\"middle\" x=\"400.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.618</text>\r\n",
       "</g>\r\n",
       "<!-- 4&#45;&gt;10 -->\r\n",
       "<g id=\"edge7\" class=\"edge\"><title>4&#45;&gt;10</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M378.3,-118.785C381.638,-106.188 385.489,-91.6529 389.037,-78.2629\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"392.5,-78.8605 391.678,-68.2976 385.733,-77.0676 392.5,-78.8605\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"395.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 5 -->\r\n",
       "<g id=\"node10\" class=\"node\"><title>5</title>\r\n",
       "<path fill=\"#e96b4c\" stroke=\"black\" d=\"M599,-187C599,-187 488,-187 488,-187 482,-187 476,-181 476,-175 476,-175 476,-131 476,-131 476,-125 482,-119 488,-119 488,-119 599,-119 599,-119 605,-119 611,-125 611,-131 611,-131 611,-175 611,-175 611,-181 605,-187 599,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"543.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">5</text>\r\n",
       "<text text-anchor=\"middle\" x=\"543.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">SibSp &lt; 0.345</text>\r\n",
       "<text text-anchor=\"middle\" x=\"543.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"543.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 90</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;5 -->\r\n",
       "<g id=\"edge9\" class=\"edge\"><title>2&#45;&gt;5</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M543.5,-237.785C543.5,-225.311 543.5,-210.938 543.5,-197.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"547,-197.298 543.5,-187.298 540,-197.298 547,-197.298\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"555\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 6 -->\r\n",
       "<g id=\"node13\" class=\"node\"><title>6</title>\r\n",
       "<path fill=\"#e96b4c\" stroke=\"black\" d=\"M795,-187C795,-187 684,-187 684,-187 678,-187 672,-181 672,-175 672,-175 672,-131 672,-131 672,-125 678,-119 684,-119 684,-119 795,-119 795,-119 801,-119 807,-125 807,-131 807,-131 807,-175 807,-175 807,-181 801,-187 795,-187\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"739.5\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">6</text>\r\n",
       "<text text-anchor=\"middle\" x=\"739.5\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">SibSp &lt; 0.345</text>\r\n",
       "<text text-anchor=\"middle\" x=\"739.5\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">split_quantile = 0.1</text>\r\n",
       "<text text-anchor=\"middle\" x=\"739.5\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples = 32</text>\r\n",
       "</g>\r\n",
       "<!-- 2&#45;&gt;6 -->\r\n",
       "<g id=\"edge12\" class=\"edge\"><title>2&#45;&gt;6</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M598.88,-237.942C622.573,-223.798 650.393,-207.191 675.008,-192.498\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"677.125,-195.31 683.917,-187.179 673.537,-189.3 677.125,-195.31\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"661.5\" y=\"-208.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 11 -->\r\n",
       "<g id=\"node11\" class=\"node\"><title>11</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M549,-68C549,-68 478,-68 478,-68 472,-68 466,-62 466,-56 466,-56 466,-12 466,-12 466,-6 472,-0 478,-0 478,-0 549,-0 549,-0 555,-0 561,-6 561,-12 561,-12 561,-56 561,-56 561,-62 555,-68 549,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"513.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">11</text>\r\n",
       "<text text-anchor=\"middle\" x=\"513.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"513.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 0/0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"513.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.000</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;11 -->\r\n",
       "<g id=\"edge10\" class=\"edge\"><title>5&#45;&gt;11</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M534.983,-118.785C531.753,-106.188 528.026,-91.6529 524.593,-78.2629\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"527.912,-77.1149 522.038,-68.2976 521.131,-78.8536 527.912,-77.1149\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"542\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 12 -->\r\n",
       "<g id=\"node12\" class=\"node\"><title>12</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M662,-68C662,-68 591,-68 591,-68 585,-68 579,-62 579,-56 579,-56 579,-12 579,-12 579,-6 585,-0 591,-0 591,-0 662,-0 662,-0 668,-0 674,-6 674,-12 674,-12 674,-56 674,-56 674,-62 668,-68 662,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"626.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">12</text>\r\n",
       "<text text-anchor=\"middle\" x=\"626.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=90</text>\r\n",
       "<text text-anchor=\"middle\" x=\"626.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 48/42</text>\r\n",
       "<text text-anchor=\"middle\" x=\"626.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.298</text>\r\n",
       "</g>\r\n",
       "<!-- 5&#45;&gt;12 -->\r\n",
       "<g id=\"edge11\" class=\"edge\"><title>5&#45;&gt;12</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M567.062,-118.785C576.35,-105.694 587.121,-90.5099 596.923,-76.693\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"599.947,-78.4789 602.879,-68.2976 594.238,-74.4286 599.947,-78.4789\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"598.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "<!-- 13 -->\r\n",
       "<g id=\"node14\" class=\"node\"><title>13</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M775,-68C775,-68 704,-68 704,-68 698,-68 692,-62 692,-56 692,-56 692,-12 692,-12 692,-6 698,-0 704,-0 704,-0 775,-0 775,-0 781,-0 787,-6 787,-12 787,-12 787,-56 787,-56 787,-62 781,-68 775,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"739.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">13</text>\r\n",
       "<text text-anchor=\"middle\" x=\"739.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"739.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 0/0</text>\r\n",
       "<text text-anchor=\"middle\" x=\"739.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.000</text>\r\n",
       "</g>\r\n",
       "<!-- 6&#45;&gt;13 -->\r\n",
       "<g id=\"edge13\" class=\"edge\"><title>6&#45;&gt;13</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M739.5,-118.785C739.5,-106.311 739.5,-91.9377 739.5,-78.657\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"743,-78.2976 739.5,-68.2976 736,-78.2976 743,-78.2976\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"751\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">yes</text>\r\n",
       "</g>\r\n",
       "<!-- 14 -->\r\n",
       "<g id=\"node15\" class=\"node\"><title>14</title>\r\n",
       "<path fill=\"#207dfb\" stroke=\"black\" d=\"M888,-68C888,-68 817,-68 817,-68 811,-68 805,-62 805,-56 805,-56 805,-12 805,-12 805,-6 811,-0 817,-0 817,-0 888,-0 888,-0 894,-0 900,-6 900,-12 900,-12 900,-56 900,-56 900,-62 894,-68 888,-68\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"852.5\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">14</text>\r\n",
       "<text text-anchor=\"middle\" x=\"852.5\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">samples=32</text>\r\n",
       "<text text-anchor=\"middle\" x=\"852.5\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">+/&#45; = 22/10</text>\r\n",
       "<text text-anchor=\"middle\" x=\"852.5\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">value=0.369</text>\r\n",
       "</g>\r\n",
       "<!-- 6&#45;&gt;14 -->\r\n",
       "<g id=\"edge14\" class=\"edge\"><title>6&#45;&gt;14</title>\r\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M771.579,-118.785C784.581,-105.323 799.72,-89.6488 813.362,-75.5233\"/>\r\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"815.911,-77.9221 820.341,-68.2976 810.876,-73.0591 815.911,-77.9221\"/>\r\n",
       "<text text-anchor=\"middle\" x=\"811.5\" y=\"-89.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">no</text>\r\n",
       "</g>\r\n",
       "</g>\r\n",
       "</svg>\r\n"
      ],
      "text/plain": [
       "<graphviz.files.Source at 0x21f0ff9cfa0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>y</th>\n",
       "      <th>$p_4$</th>\n",
       "      <th>$l_4$</th>\n",
       "      <th>$r_4$</th>\n",
       "      <th>$\\gamma_4$</th>\n",
       "      <th>$l_5$</th>\n",
       "      <th>$p_5$</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0.158819</td>\n",
       "      <td>-1.667041</td>\n",
       "      <td>-0.158819</td>\n",
       "      <td>-0.272572</td>\n",
       "      <td>-1.803327</td>\n",
       "      <td>0.141447</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>0.158819</td>\n",
       "      <td>-1.667041</td>\n",
       "      <td>-0.158819</td>\n",
       "      <td>-0.272572</td>\n",
       "      <td>-1.803327</td>\n",
       "      <td>0.141447</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0.880733</td>\n",
       "      <td>1.999390</td>\n",
       "      <td>0.119267</td>\n",
       "      <td>0.617864</td>\n",
       "      <td>2.308322</td>\n",
       "      <td>0.909564</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>0.158819</td>\n",
       "      <td>-1.667041</td>\n",
       "      <td>-0.158819</td>\n",
       "      <td>-0.272572</td>\n",
       "      <td>-1.803327</td>\n",
       "      <td>0.141447</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>0.346310</td>\n",
       "      <td>-0.635300</td>\n",
       "      <td>-0.346310</td>\n",
       "      <td>-0.272572</td>\n",
       "      <td>-0.771586</td>\n",
       "      <td>0.316136</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>663</th>\n",
       "      <td>0</td>\n",
       "      <td>0.158819</td>\n",
       "      <td>-1.667041</td>\n",
       "      <td>-0.158819</td>\n",
       "      <td>-0.272572</td>\n",
       "      <td>-1.803327</td>\n",
       "      <td>0.141447</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>664</th>\n",
       "      <td>1</td>\n",
       "      <td>0.181128</td>\n",
       "      <td>-1.508723</td>\n",
       "      <td>0.818872</td>\n",
       "      <td>0.298326</td>\n",
       "      <td>-1.359560</td>\n",
       "      <td>0.204312</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>665</th>\n",
       "      <td>0</td>\n",
       "      <td>0.346310</td>\n",
       "      <td>-0.635300</td>\n",
       "      <td>-0.346310</td>\n",
       "      <td>-0.272572</td>\n",
       "      <td>-0.771586</td>\n",
       "      <td>0.316136</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>666</th>\n",
       "      <td>0</td>\n",
       "      <td>0.158819</td>\n",
       "      <td>-1.667041</td>\n",
       "      <td>-0.158819</td>\n",
       "      <td>-0.272572</td>\n",
       "      <td>-1.803327</td>\n",
       "      <td>0.141447</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>667</th>\n",
       "      <td>0</td>\n",
       "      <td>0.175606</td>\n",
       "      <td>-1.546405</td>\n",
       "      <td>-0.175606</td>\n",
       "      <td>-0.272572</td>\n",
       "      <td>-1.682691</td>\n",
       "      <td>0.156739</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>668 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     y     $p_4$     $l_4$     $r_4$  $\\gamma_4$     $l_5$     $p_5$\n",
       "0    0  0.158819 -1.667041 -0.158819   -0.272572 -1.803327  0.141447\n",
       "1    0  0.158819 -1.667041 -0.158819   -0.272572 -1.803327  0.141447\n",
       "2    1  0.880733  1.999390  0.119267    0.617864  2.308322  0.909564\n",
       "3    0  0.158819 -1.667041 -0.158819   -0.272572 -1.803327  0.141447\n",
       "4    0  0.346310 -0.635300 -0.346310   -0.272572 -0.771586  0.316136\n",
       "..  ..       ...       ...       ...         ...       ...       ...\n",
       "663  0  0.158819 -1.667041 -0.158819   -0.272572 -1.803327  0.141447\n",
       "664  1  0.181128 -1.508723  0.818872    0.298326 -1.359560  0.204312\n",
       "665  0  0.346310 -0.635300 -0.346310   -0.272572 -0.771586  0.316136\n",
       "666  0  0.158819 -1.667041 -0.158819   -0.272572 -1.803327  0.141447\n",
       "667  0  0.175606 -1.546405 -0.175606   -0.272572 -1.682691  0.156739\n",
       "\n",
       "[668 rows x 7 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "iterate(4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEWCAYAAAB8LwAVAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3deXxU5dn/8c+VjRAgQEgIEJCAgBAQIgbclypYxAW1VrG1PrV9Hmv7uCDaij7+bGs3rZZiq6211dodXKi1boAbuFUI+67IIgGBQNj3JNfvjznQNA5kgEzOJPN9v155OXOWmWtuw3xzzn2f+5i7IyIiUltK2AWIiEhiUkCIiEhUCggREYlKASEiIlEpIEREJCoFhIiIRKWAkEbBzFaa2ZCw6wAwsx+a2UYzWxd2LSLxpIAQOQJm1gW4HShy9w6H2CbbzMaZ2SdmtsPMlgXPc2N4/a+a2Tu1lj1lZvuC19puZjPN7Jz6+USHrON7ZvbneL6HJD4FhMiR6QpscvcN0VaaWQbwOtAXGAZkA6cDm4DBx/C+P3X3lkBr4NfARDNLPYbXE6mTAkIaHTNrFvxFvjb4GWdmzYJ1uWb2opltMbMKM3vbzFKCdXea2Zrgr/ClZnb+IV6/tZn90czKzWyVmd1jZinBKa4pQKfgr/mnoux+HXAccLm7L3L3anff4O4/cPeXg9cfY2YfB3UsM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EBGRqBQQIiISlQJCRESi+v//Ia65AsELzAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(loss[1:])\n",
    "plt.title('loss of CatBoost')\n",
    "plt.xlabel('iteratoin')\n",
    "plt.ylabel('loss')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "class CatBoostClassifier():\n",
    "    \n",
    "    n_estimators = 100\n",
    "    \n",
    "    #now let's get started\n",
    "    learning_rate=0.2\n",
    "    trees = []\n",
    "    loss = []\n",
    "    residuals = np.zeros([100,n_train])\n",
    "    probabilities = np.zeros([100,n_train])\n",
    "    predictions = np.zeros([100,n_train])\n",
    "    log_of_odds = np.zeros([100,n_train])\n",
    "    gamma = np.zeros([100,n_train])\n",
    "    log_of_odds[0] = [0] * n_train\n",
    "\n",
    "    def __init__(self, n_estimators=100):\n",
    "        self.n_estimators = n_estimators\n",
    "        pass\n",
    "    \n",
    "    def iterate(self, i, X_train, y_train):\n",
    "        n_train=len(y_train)\n",
    "        t = ObliviousTree(max_depth=3, gamma=5)\n",
    "        t.fit(X_train,self.residuals[i], self.probabilities[i])\n",
    "        #t.prune()\n",
    "        self.trees.append(t)\n",
    "        \n",
    "\n",
    "        self.gamma[i]=t.predict(X_train)\n",
    "        self.log_of_odds[i+1] = self.log_of_odds[i] + self.learning_rate * self.gamma[i]\n",
    "        self.probabilities[i+1] = np.array([np.exp(odds)/(np.exp(odds)+1) for odds in self.log_of_odds[i+1]])\n",
    "        self.predictions[i+1] = (self.probabilities[i+1]>0.5)*1.0\n",
    "        self.residuals[i+1]=y_train-self.probabilities[i+1]\n",
    "        _loss=np.sum(-y_train * self.log_of_odds[i+1] + np.log(1+np.exp(self.log_of_odds[i+1])))/n_train\n",
    "        self.loss.append(_loss)\n",
    "\n",
    "    def fit(self, X_train, y_train):\n",
    "        n_train=len(y_train)\n",
    "        #n_estimators=10\n",
    "        #now let's get started\n",
    "        self.learning_rate=0.3\n",
    "        self.loss = []\n",
    "        self.trees = []\n",
    "        self.residuals = np.zeros([self.n_estimators+1, n_train])\n",
    "        self.probabilities = np.zeros([self.n_estimators+1, n_train])\n",
    "        self.predictions = np.zeros([self.n_estimators+1, n_train])\n",
    "        self.log_of_odds = np.zeros([self.n_estimators+1, n_train])\n",
    "        self.gamma = np.zeros([self.n_estimators+1, n_train])\n",
    "        self.log_of_odds[0] = [0] * n_train\n",
    "        self.probabilities[0] = [0.5] * n_train\n",
    "        self.predictions[0] = [1] * n_train\n",
    "        self.residuals[0] = y_train - probabilities[0]\n",
    "        loss0=-(y_train*np.log(probabilities[0])+(1-y_train)*np.log(1-probabilities[0]))\n",
    "        loss0 = np.sum(loss0) / n_train\n",
    "        self.loss.append(loss0)\n",
    "        \n",
    "        for i in range(self.n_estimators):\n",
    "            self.iterate(i, X_train, y_train)\n",
    "\n",
    "    def predict_proba(self, X):\n",
    "        X = np.array(X)\n",
    "        log_of_odds = np.array([0.0] * X.shape[0])\n",
    "        for t in self.trees:\n",
    "            log_of_odds+=t.predict(X)\n",
    "        results = np.array([np.exp(odds)/(np.exp(odds)+1) for odds in log_of_odds])\n",
    "        return results\n",
    "    \n",
    "    def predict(self, X):\n",
    "        proba = self.predict_proba(X)\n",
    "        results = (proba>0.5) * 1.0\n",
    "        return results\n",
    "    \n",
    "    def accuracy(self, X, y):\n",
    "        n=len(y)\n",
    "        y_hat = self.predict(X)\n",
    "        right = np.sum(y_hat == y)\n",
    "        return right/n * 1.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = CatBoostClassifier(n_estimators=100)\n",
    "model.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8323353293413174"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.accuracy(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8026905829596412"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.accuracy(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD4CAYAAADiry33AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAe0klEQVR4nO3de3Bc5Znn8e/TV6lbknU3+IIliCGYJJAgDIRcSAisSbIhmcrMOBk2mdqpOMyGmexMdndIzVZq55+tnWE2lcxChvUQNrOzSRwqXOLJEENuQCYVwDLh4gsG46tsbMtX3dXq7mf/OEdyW0iobUtu+/TvU6VS9+lz1O9bht95+znvedvcHRERia5YpRsgIiJzS0EvIhJxCnoRkYhT0IuIRJyCXkQk4hKVbsBUWltbvaOjo9LNEBE5b2zYsOGQu7dN9do5GfQdHR10d3dXuhkiIucNM9s13Wsq3YiIRFxZQW9mK8xsq5ltM7O7pnj9P5vZC+HPRjMrmFlzOceKiMjcmjHozSwO3AvcCiwDPmNmy0r3cfe73f0qd78K+CrwlLsfKedYERGZW+WM6JcD29x9u7vngDXAbW+x/2eA75/msSIiMsvKCfqFwJ6S5z3htjcxswywAnjoNI5dZWbdZtbd29tbRrNERKQc5QS9TbFtupXQ/i3wa3c/cqrHuvtqd+9y9662tilnCImIyGkoJ+h7gMUlzxcB+6bZdyUnyjaneqy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VxnZpnwv/ObCK5BRbnP46br41pgpZmlzawTWAo8d1rv4O6R+AE+CrwKvA78ZaXbM0d9fB/BR7eXgBfCn48CLQRX618LfzdXuq1z1P8bgR+HjyPdZ+AqoDv8t34UaKqCPv8V8AqwEfgnIB21PgPfJ7gGMUYwYv+jt+oj8Jdhpm0Fbj3d99USCCIiEReV0o2IiExDQS8iEnEKehGRiFPQi4hEnIJeRCTiFPQiIhGnoBcRibj/D6GmvSvdyNn9AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(model.loss)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_test = pd.read_csv(\"data/titanic_test.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_submit = df_test.copy()\n",
    "df_submit['Survived'] = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_submit=df_submit[['PassengerId', 'Survived']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PassengerId</th>\n",
       "      <th>Survived</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>892</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>893</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>894</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>895</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>896</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>413</th>\n",
       "      <td>1305</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>414</th>\n",
       "      <td>1306</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>415</th>\n",
       "      <td>1307</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>416</th>\n",
       "      <td>1308</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>417</th>\n",
       "      <td>1309</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>418 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     PassengerId  Survived\n",
       "0            892         0\n",
       "1            893         0\n",
       "2            894         0\n",
       "3            895         0\n",
       "4            896         0\n",
       "..           ...       ...\n",
       "413         1305         0\n",
       "414         1306         0\n",
       "415         1307         0\n",
       "416         1308         0\n",
       "417         1309         0\n",
       "\n",
       "[418 rows x 2 columns]"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_submit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_test = data_preprocess(df_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_test = target_statistics(df_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Pclass</th>\n",
       "      <th>Sex</th>\n",
       "      <th>SibSp</th>\n",
       "      <th>Parch</th>\n",
       "      <th>Fare</th>\n",
       "      <th>Embarked</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.242506</td>\n",
       "      <td>1</td>\n",
       "      <td>0.345426</td>\n",
       "      <td>0.343687</td>\n",
       "      <td>7.8292</td>\n",
       "      <td>0.389573</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.242506</td>\n",
       "      <td>0</td>\n",
       "      <td>0.535522</td>\n",
       "      <td>0.343687</td>\n",
       "      <td>7.0000</td>\n",
       "      <td>0.336993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.472585</td>\n",
       "      <td>1</td>\n",
       "      <td>0.345426</td>\n",
       "      <td>0.343687</td>\n",
       "      <td>9.6875</td>\n",
       "      <td>0.389573</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.242506</td>\n",
       "      <td>1</td>\n",
       "      <td>0.345426</td>\n",
       "      <td>0.343687</td>\n",
       "      <td>8.6625</td>\n",
       "      <td>0.336993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.242506</td>\n",
       "      <td>0</td>\n",
       "      <td>0.535522</td>\n",
       "      <td>0.550143</td>\n",
       "      <td>12.2875</td>\n",
       "      <td>0.336993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>413</th>\n",
       "      <td>0.242506</td>\n",
       "      <td>1</td>\n",
       "      <td>0.345426</td>\n",
       "      <td>0.343687</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>0.336993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>414</th>\n",
       "      <td>0.629062</td>\n",
       "      <td>0</td>\n",
       "      <td>0.345426</td>\n",
       "      <td>0.343687</td>\n",
       "      <td>108.9000</td>\n",
       "      <td>0.553068</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>415</th>\n",
       "      <td>0.242506</td>\n",
       "      <td>1</td>\n",
       "      <td>0.345426</td>\n",
       "      <td>0.343687</td>\n",
       "      <td>7.2500</td>\n",
       "      <td>0.336993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>416</th>\n",
       "      <td>0.242506</td>\n",
       "      <td>1</td>\n",
       "      <td>0.345426</td>\n",
       "      <td>0.343687</td>\n",
       "      <td>8.0500</td>\n",
       "      <td>0.336993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>417</th>\n",
       "      <td>0.242506</td>\n",
       "      <td>1</td>\n",
       "      <td>0.535522</td>\n",
       "      <td>0.550143</td>\n",
       "      <td>22.3583</td>\n",
       "      <td>0.553068</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>418 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       Pclass  Sex     SibSp     Parch      Fare  Embarked\n",
       "0    0.242506    1  0.345426  0.343687    7.8292  0.389573\n",
       "1    0.242506    0  0.535522  0.343687    7.0000  0.336993\n",
       "2    0.472585    1  0.345426  0.343687    9.6875  0.389573\n",
       "3    0.242506    1  0.345426  0.343687    8.6625  0.336993\n",
       "4    0.242506    0  0.535522  0.550143   12.2875  0.336993\n",
       "..        ...  ...       ...       ...       ...       ...\n",
       "413  0.242506    1  0.345426  0.343687    8.0500  0.336993\n",
       "414  0.629062    0  0.345426  0.343687  108.9000  0.553068\n",
       "415  0.242506    1  0.345426  0.343687    7.2500  0.336993\n",
       "416  0.242506    1  0.345426  0.343687    8.0500  0.336993\n",
       "417  0.242506    1  0.535522  0.550143   22.3583  0.553068\n",
       "\n",
       "[418 rows x 6 columns]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_test"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_hat=model.predict(df_test.values)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_submit['Survived'] = y_hat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_submit['Survived'] = df_submit['Survived'].astype(int)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df_submit.to_csv(\"data/titanic_catboost.csv\", index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "I submitted it to kaggle the accuracy is 0.77511, not bad. It is even much better than some attempts which I used XGB."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
